Flicker free panel
-
I am using these lines, to avoid flicker in my program:
SetStyle(ControlStyles.UserPaint, true); SetStyle(ControlStyles.DoubleBuffer, true); SetStyle(ControlStyles.AllPaintingInWmPaint, true); private void timer1_Tick(object sender, System.EventArgs e) { Invalidate(); } private void Form1_Paint(object sender, System.Windows.Forms.PaintEventArgs e) { Graphics g = e.Graphics; ... }
However, it dont work for panels, only for the main window, if i try like this:private void timer1_Tick(object sender, System.EventArgs e) { panel1.Invalidate(); } private void panel1_Paint(object sender, System.Windows.Forms.PaintEventArgs e) { Graphics g = e.Graphics; ... }
It there a simple way to make panels flicker free? -
I am using these lines, to avoid flicker in my program:
SetStyle(ControlStyles.UserPaint, true); SetStyle(ControlStyles.DoubleBuffer, true); SetStyle(ControlStyles.AllPaintingInWmPaint, true); private void timer1_Tick(object sender, System.EventArgs e) { Invalidate(); } private void Form1_Paint(object sender, System.Windows.Forms.PaintEventArgs e) { Graphics g = e.Graphics; ... }
However, it dont work for panels, only for the main window, if i try like this:private void timer1_Tick(object sender, System.EventArgs e) { panel1.Invalidate(); } private void panel1_Paint(object sender, System.Windows.Forms.PaintEventArgs e) { Graphics g = e.Graphics; ... }
It there a simple way to make panels flicker free?I wonder where you have written these lines of code:
SetStyle(ControlStyles.UserPaint, true);
SetStyle(ControlStyles.DoubleBuffer, true);
SetStyle(ControlStyles.AllPaintingInWmPaint, true);If you created your custom panel, so it should work flicker free.
-
I wonder where you have written these lines of code:
SetStyle(ControlStyles.UserPaint, true);
SetStyle(ControlStyles.DoubleBuffer, true);
SetStyle(ControlStyles.AllPaintingInWmPaint, true);If you created your custom panel, so it should work flicker free.
-
custom panel? I just drag a panel from the toolbox. The lines a placed in the constructor.
That's why it's not flicker free. You should make a custom panel, which derives from Panel control, and then you just need to add those lines of code in the constructor of your custom panel. After compiling and adding it to your form, it will work flicker free. This article may help you: Flicker free drawing using GDI+ and C#[^]
-
I am using these lines, to avoid flicker in my program:
SetStyle(ControlStyles.UserPaint, true); SetStyle(ControlStyles.DoubleBuffer, true); SetStyle(ControlStyles.AllPaintingInWmPaint, true); private void timer1_Tick(object sender, System.EventArgs e) { Invalidate(); } private void Form1_Paint(object sender, System.Windows.Forms.PaintEventArgs e) { Graphics g = e.Graphics; ... }
However, it dont work for panels, only for the main window, if i try like this:private void timer1_Tick(object sender, System.EventArgs e) { panel1.Invalidate(); } private void panel1_Paint(object sender, System.Windows.Forms.PaintEventArgs e) { Graphics g = e.Graphics; ... }
It there a simple way to make panels flicker free?To note, it's much faster to use
SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.DoubleBuffer | ControlStyles.UserPaint, true);
. This results in fewer calls since all three enumerations are OR'd together at compile time. That's what theFlagsAttribute
allows on an enumeration likeControlStyles
(all enumerations denoting plurality in the .NET FCL typically have theFlagsAttribute
).Microsoft MVP, Visual C# My Articles
-
To note, it's much faster to use
SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.DoubleBuffer | ControlStyles.UserPaint, true);
. This results in fewer calls since all three enumerations are OR'd together at compile time. That's what theFlagsAttribute
allows on an enumeration likeControlStyles
(all enumerations denoting plurality in the .NET FCL typically have theFlagsAttribute
).Microsoft MVP, Visual C# My Articles