c# - Panel DoubleBuffered property stopped the drawing, is invisible -
i have component, inherited panel, overriding onpaint event draw graph 500 points. since need selection on graph, flickering. have found doublebuffered property when set true, in panel constructor, drawing disappears. debug , see drawing methods still execute there nothing on panel. know why happen?
this .net 3.5 - c#. winforms application
try { graphics g = e.graphics; //draw _grapharea: g.drawrectangle(pens.black, _grapharea); _drawingobjectlist.drawgraph(g, _mainlinepen, _difflinepen, _dotpen, _dotbrush, _notselectedbrush, _selectedbrush); drawselectionrectangle(g); g.dispose(); } catch (exception ex) { messagebox.show(ex.message); }
panel descendant constructor:
this.backcolor = color.white; this.setstyle(controlstyles.resizeredraw, true); this.setstyle(controlstyles.userpaint, true); this.setstyle(controlstyles.allpaintinginwmpaint, true); this.setstyle(controlstyles.optimizeddoublebuffer, true); this.updatestyles();
try using controlstyles.optimizeddoublebuffered
instead. it's faster , works better. make sure controlstyles.allpaintinginwmpaint
, controlstyles.userpaint
enabled.
now, onpaint()
should stuff draw window , method must called invalidation or using refresh()
; must never call onpaint()
yourself. not dispose graphics
object. if fail of conditions, flickering , various other drawing bugs might occur.
class mycontrol : usercontrol { public mycontrol() { setstyle(controlstyles.allpaintinginwmpaint, true); setstyle(controlstyles.userpaint, true); setstyle(controlstyles.optimizeddoublebuffer, true); } protected override void onpaint(painteventargs e) { e.graphics.clear(color.red); } void randomeventthatrequiresrefresh(object sender, eventargs e) { refresh(); } }
Comments
Post a Comment