2
votes

I have developed a WinForms application that uses a Main form and TabControl. On the tab control is several tabs that use controls from a library. I have noticed recently that upon resizing of the application the entire application flickers like crazy.

What have I tried?

I tried adding the below code to the _load event of the form and of one of the controls. I then switched to that control via the tab and tried to resize but no difference the flicker is still really bad.

DoubleBuffered = true; 

EDIT 1

I also have WPF controls on one tab. I am curious if that would cause the flickers also.

1
What have you changed just before you noticed the flickering? Do you have many threads? Do you have some actions you do on the SizeChanged event? Anything like that? My guess is that the resizing causes action-and-reaction that eventually, directly or indirectly, run a piece of code of yours, that should either be threaded, efficientified or removed and handled in another manner.SimpleVar
I do kick off several threads to load background data but it only happens per the users interaction. I double checked the entire solution and didn't find any code related to sizing events either. I am going to have to dig deeper and see what I can find. I have extra information I am editing the main question with.meanbunny
Is this a new application? If so, I wonder why you're trying to mix win forms and WPF, instead of just jumping to WPF. What happens if you remove the WPF tab? I doubt that is the issue, but it will at least remove that possibility from your mind. How are your elements arranged? Through fixed positions, or docking?Phil
I tried removing the tab and nothing. They are fixed positions and are anchored.meanbunny
Well it is about a year into development, but we have coded everything so modular that moving to WPF wouldn't be that monumental. We stayed on WinForms for performance reasons and the WPF controls we added were for appearance mainly.meanbunny

1 Answers

0
votes

There is Couple of ways to fix this problem :

For the form resize Events (onResizeBegin & on ResizeEnd) use the following code :

protected override void OnResizeBegin(EventArgs e) 
 {
    SuspendLayout();
    base.OnResizeBegin(e);
 }

protected override void OnResizeEnd(EventArgs e) 
 {
    ResumeLayout();
    base.OnResizeEnd(e);
 }

- in the form Contstructor use this code :

this.SetStyle( ControlStyles.AllPaintingInWmPaint, true );
this.SetStyle( ControlStyles.UserPaint, true );
this.SetStyle( ControlStyles.OptimizedDoubleBuffer, true );
this.SetStyle( ControlStyles.ResizeRedraw, true );