GDI+ flicker when drawing to a panel
-
I have a panel inside a form im drawing to becuase the drawing space needs to be bigger than the form and the user needs to be able to scroll round the image using the form scroll bars.. i have used SetStyle(ControlStyles.DoubleBuffer, true); SetStyle(ControlStyles.UserPaint, true); SetStyle(ControlStyles.AllPaintingInWmPaint, true); to try and stop the flicker but it only works when the form itself is drawn to. How do i get double buffering to work on the panel? Thanks.
-
I have a panel inside a form im drawing to becuase the drawing space needs to be bigger than the form and the user needs to be able to scroll round the image using the form scroll bars.. i have used SetStyle(ControlStyles.DoubleBuffer, true); SetStyle(ControlStyles.UserPaint, true); SetStyle(ControlStyles.AllPaintingInWmPaint, true); to try and stop the flicker but it only works when the form itself is drawn to. How do i get double buffering to work on the panel? Thanks.
-
This problem has been plauging me for weeks.... then a minuite i post this i stubmle across the solution (more by luck than judgment) .. sods law, hey? All sorted now thanks. :D
You care to post your solution? There are thousands of others with the same flicker problem.
Tech, life, family, faith: Give me a visit. I'm currently blogging about: Conversation With a Muslim Judah Himango
-
You care to post your solution? There are thousands of others with the same flicker problem.
Tech, life, family, faith: Give me a visit. I'm currently blogging about: Conversation With a Muslim Judah Himango
Yeah sorry about that... I hate it when I search for a problem and the OP says "sorted" and it just dies right then and there, to. So here goes: My Drawing function looked like this(Though it has been drasticly cut down to the bare minimum for readability):
private void DrawMyStuff() { System.Drawing.Graphics myGraphics; myGraphics = myPanel.CreateGraphics(); MyGraphics.DrawImage(myBitmap, x*Size,y*Size); MyGraphics.Dispose(); }
My panels paint method looked like thisprivate void myPanel_Paint(object sender, System.Windows.Forms.PaintEventArgs e) { DrawMyStuff(); }
I have since changed it to look like this:private void DrawMyStuff(Graphics g) { g.DrawImage(myBitmap, x, y); g.Dispose(); }
&private void myPanel_Paint(object sender, System.Windows.Forms.PaintEventArgs e) { DrawMyStuff(e.Graphics); }
I think my problem was re-assigning the graphics object every time and in a way bybassing the double buffering by recreating the drawing surface constantly. Hope that helps some people...