Possible Duplicates:
How do I double buffer a Panel in C#? c# panel for drawing graphics and scrolling
I draw a bitmap on a panel, i use zooming on the same panel. While zooming the panel is continuously flickering. Why do not panel have the DoubleBuffered property?
Code:
Graphics g = Graphics.FromHwnd(panel.Handle);
开发者_运维技巧 if (newImage == true)
{
g.Clear(SystemColors.Control);
newImage = false;
}
g.DrawImage(bmp, hOffset, vOffset);
g.Dispose();
Add this code inside the constructor
this.SetStyle(ControlStyles.AllPaintingInWmPaint |ControlStyles.UserPaint |ControlStyles.DoubleBuffer, true);
use this.
System.Drawing.BufferedGraphics
I am a game developer.In games we first draw all objects in a backbuffer and then copy or flip it to frontbuffer.You can use
System.Drawing.BufferedGraphics
as backbuffer and render it to graphics object.
System.Drawing.Graphics
for example:
System.Drawing.Graphics g = this.CreateGraphics();
System.Drawing.BufferedGraphicsContext dc = new BufferedGraphicsContext();
BufferedGraphics backbuffer = dc.Allocate(g, new Rectangle(new Point(0, 0), g.VisibleClipBounds.Size.ToSize()));
backbuffer.Graphics.DrawImage(Image.FromFile(@"c:\test.jpg"), new Point(10, 10));
backbuffer.Render(g);
Where are you painting the bitmap?
If not in the Paint
event or OnPaint
override, then it is wrong.
To answer your question, only forms have the DoubleBuffered
property, IIRC.
Im not 100% sure but cant you activate DoubleBuffered on the form/window instead?
And one tip if your going to use gui with alot of effects i would go with WPF instead of winforms..
You can also override OnPaint and OnPaintBackground..
精彩评论