Click to See Complete Forum and Search --> : GDI Drawing on usercontrol causes excessive tearing


Grofit
January 10th, 2009, 11:55 AM
Hey,

I had a form that generated a simple graph that you can manipulate, all done through GDI and it works great, although i have double buffering on the form.

Now im having to change alot of these forms into usercontrols so that i can house them all within tab pages in another form...

Anyway now ive put them into the tab control and there is alot of tearing whenever i change the values (thats when it refreshes), the containers used to be:

Form - GDI Drawing

Now its

Form
|
| - TabPanelControl
| |
| | - TabPageControl
| | |
| | | - CustomControl - GDI Drawing


So im wondering if its down to it being placed in another control, ive set the form to double buffered, anyway if anyone has any advice let me know!

Grofit
January 10th, 2009, 01:57 PM
Just incase anyone else has this problem i was able to solve this problem by adding this to the constructor of my control:


this.SetStyle(ControlStyles.DoubleBuffer | ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint, true);
this.UpdateStyles();

BigEd781
January 11th, 2009, 12:28 AM
I didn't really know what you meant by 'tearing', but I guess now that you meant flashing. It was happening because your grid was no longer double buffered once you removed it as a child of the form. Setting a form to double buffered means that its graphics object will be double buffered, it does not propagate down to all the children.