EDN Admin
Well-known member
Dear All,
I have created a custom Control that inherits from System.Windows.Forms.UserControl and acts basically like a Progress Bar. During the development process, I realised that the control was flickering even though I was double buffering it manually (by
drawing onto a bitmap and drawing that bitmap onto the Graphics object of the control.
I assumed that this was happening because, in any case, the controls bitmap was being drawn repeatedly when the control was updated. After a little research on the internet, I decided to use the Control.SetStyles. The problem is that when I try to do that,
an ArgumentException for the method Application.Run(new MainWindow()); was occurring.
Ive tried calling the method in the contructor:
<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; public <span style="color:Blue; partial <span style="color:Blue; class SmoothProgressTube : UserControl
{
<span style="color:Blue; public SmoothProgressTube()
{
InitializeComponent();
SetStyle(ControlStyles.OptimizedDoubleBuffer |
ControlStyles.UserPaint |
ControlStyles.AllPaintingInWmPaint, <span style="color:Blue; true);
}
<span style="color:Green; // and the rest of the code...
}
[/code]
Ive also tried putting it into the Load event:
<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; private <span style="color:Blue; void SmoothProgressTube_Load(<span style="color:Blue; object sender, EventArgs e)
{
<span style="color:Green; //this.DoubleBuffered = true; // Ive tried this as well. Guess what? It doesnt work...
SetStyle(ControlStyles.OptimizedDoubleBuffer |
ControlStyles.UserPaint |
ControlStyles.AllPaintingInWmPaint, <span style="color:Blue; true);
<span style="color:Green; //And the rest of the code follows...
}
[/code]
If I remove the SetStyle method. The program works fine. But it flickers.
Any suggestions?
Thanks in advance. <hr class="sig A hobbyist programmer, Anonymous.
View the full article
I have created a custom Control that inherits from System.Windows.Forms.UserControl and acts basically like a Progress Bar. During the development process, I realised that the control was flickering even though I was double buffering it manually (by
drawing onto a bitmap and drawing that bitmap onto the Graphics object of the control.
I assumed that this was happening because, in any case, the controls bitmap was being drawn repeatedly when the control was updated. After a little research on the internet, I decided to use the Control.SetStyles. The problem is that when I try to do that,
an ArgumentException for the method Application.Run(new MainWindow()); was occurring.
Ive tried calling the method in the contructor:
<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; public <span style="color:Blue; partial <span style="color:Blue; class SmoothProgressTube : UserControl
{
<span style="color:Blue; public SmoothProgressTube()
{
InitializeComponent();
SetStyle(ControlStyles.OptimizedDoubleBuffer |
ControlStyles.UserPaint |
ControlStyles.AllPaintingInWmPaint, <span style="color:Blue; true);
}
<span style="color:Green; // and the rest of the code...
}
[/code]
Ive also tried putting it into the Load event:
<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; private <span style="color:Blue; void SmoothProgressTube_Load(<span style="color:Blue; object sender, EventArgs e)
{
<span style="color:Green; //this.DoubleBuffered = true; // Ive tried this as well. Guess what? It doesnt work...
SetStyle(ControlStyles.OptimizedDoubleBuffer |
ControlStyles.UserPaint |
ControlStyles.AllPaintingInWmPaint, <span style="color:Blue; true);
<span style="color:Green; //And the rest of the code follows...
}
[/code]
If I remove the SetStyle method. The program works fine. But it flickers.
Any suggestions?
Thanks in advance. <hr class="sig A hobbyist programmer, Anonymous.
View the full article