doublebuffered - C#, double buffer in WinForms? -


        private void button3_click(object sender, eventargs e)     {          this.doublebuffered = true;              (int = 0; < 350; i++)             {                 using (graphics g = this.creategraphics() )                 {                     g.clear(color.cadetblue);                     g.drawimage(properties.resources._256, 100, 100, i-150, i-150);                 }             }     } 

yet thought have doublebuffered set true, image still flickers. ideas doing wrong? thanks!

as neil noted, don't need (and shouldn't) create new graphics object in each iteration of loop. these relatively expensive resources , should not created willy nilly.

also, shouldn't painting inside of button click handler calling creategraphics. can lead problems, notably drawing being "undone" when paint handler invoked (i.e., every time window receives wm_paint message , refreshed). should of painting overriding onpaint , call invalidate() when need update form.

as flickering, setting doublebuffered true take care of it, rolling own double buffering trivial. give try. realize drawing in loop isn't want do. use timer if want update once per interval. code being executed fast loop can execute, not desirable.

private void sometimer_tick( ... ) {     invalidate(); } protected override void onpaint( painteventargs e ) {     using( var tempbmp = new bitmap( ... ) )     using( var g = graphics.fromimage( tempbmp ) )     {         // draw tempbmp         e.graphics.drawimage( tempbmp, new point( 0, 0 ) );     } } 

Comments

Popular posts from this blog

linux - Mailx and Gmail nss config dir -

c# - Is it possible to remove an existing registration from Autofac container builder? -

php - Mysql PK and FK char(36) vs int(10) -