how to avoid panel flicker ?
-
Hi, I'm desperate: I cannot eliminate that fastidious flicker that occurs when a panel is redrawn (it has to been redrawn every 150ms so it's not a CPU issue). I've tried with
this.SetStyle( ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint | ControlStyles.DoubleBuffer,true);
after the "InitializeComponent();" call, but it doesn't help. Then I tried doing all drawing operations on a Bitmap, and at the end draw the Bitmap on the form: no relevant effects. (a sort of manual doubleBuffer) the source code can be found at this URL: http://utenti.lycos.it/yuppygames/codeproject/flicker.zip Please, can you check my code or suggest another method? thank you -
Hi, I'm desperate: I cannot eliminate that fastidious flicker that occurs when a panel is redrawn (it has to been redrawn every 150ms so it's not a CPU issue). I've tried with
this.SetStyle( ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint | ControlStyles.DoubleBuffer,true);
after the "InitializeComponent();" call, but it doesn't help. Then I tried doing all drawing operations on a Bitmap, and at the end draw the Bitmap on the form: no relevant effects. (a sort of manual doubleBuffer) the source code can be found at this URL: http://utenti.lycos.it/yuppygames/codeproject/flicker.zip Please, can you check my code or suggest another method? thank youDrawing the bitmap directly on to your form instead of using a Panel will help. Get rid of panel1 completely and move the drawing code to an override of Form1. Try protected override void OnPaint(PaintEventArgs e) { base.OnPaint (e); e.Graphics.DrawImage( //draw shade shade barran, new Rectangle(160, 4, 299, 32), // destination rectangle 0.0f, // source rectangle x 0.0f, // source rectangle y 299, // source rectangle width 32, // source rectangle height GraphicsUnit.Pixel, imageAtt); e.Graphics.DrawImageUnscaled(temp2,new Rectangle(160+xtitolo,7,287,27)); //draw title } Then in timertitolo_Tick method Invalidate() the form rather than panel1
-
Drawing the bitmap directly on to your form instead of using a Panel will help. Get rid of panel1 completely and move the drawing code to an override of Form1. Try protected override void OnPaint(PaintEventArgs e) { base.OnPaint (e); e.Graphics.DrawImage( //draw shade shade barran, new Rectangle(160, 4, 299, 32), // destination rectangle 0.0f, // source rectangle x 0.0f, // source rectangle y 299, // source rectangle width 32, // source rectangle height GraphicsUnit.Pixel, imageAtt); e.Graphics.DrawImageUnscaled(temp2,new Rectangle(160+xtitolo,7,287,27)); //draw title } Then in timertitolo_Tick method Invalidate() the form rather than panel1
thank you very much. I did what you said and now it works. I can't believe it was panel's fault! I created that panel because I wanted to avoid repainting every single pixel of the form thinking it was faster :mad: if anyone wants to see the correct code, click here: http://utenti.lycos.it/yuppygames/codeproject/flicker2.zip thank you again colderthanfusion