Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why do my WinForms controls flicker and resize slowly?

I'm making a program where I have a lot of panels and panels in panels.

I have a few custom drawn controls in these panels.

The resize function of 1 panel contains code to adjust the size and position of all controls in that panel.

Now as soon as I resize the program, the resize of this panel gets actived. This results in a lot of flickering of the components in this panel.

All user drawn controls are double buffered.

Can some one help me solve this problem?

like image 956
user575579 Avatar asked Jan 14 '11 11:01

user575579


People also ask

How to avoid flickering in windows forms c#?

use control. DoubleBuffered property. set it to true. DoubleBuffered allows Control redraws its surface using secondary buffer to avoid flickering.

How do I resize Winforms?

By dragging either the right edge, bottom edge, or the corner, you can resize the form. The second way you can resize the form while the designer is open, is through the properties pane. Select the form, then find the Properties pane in Visual Studio. Scroll down to size and expand it.


1 Answers

To get rid of the flicker while resizing the win form, suspend the layout while resizing. Override the forms resizebegin/resizeend methods as below.

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

This will leave the controls intact (as they where before resizing) and force a redraw when the resize operation is completed.

like image 79
Dan Avatar answered Sep 29 '22 18:09

Dan