Tag Archives: form

Prevent panels to be repainted on a form resize

To prevent lots of flicker during resizing disable the real-time resizing of the child controls.
To do so override both the Form OnResizeBegin and OnResizeEnd events.

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

protected override void OnResizeEnd(EventArgs e) 
{
    ResumeLayout();
    base.OnResizeEnd(e);
}
Lastest update in January 2012, inital post in January 2012

Find the active (Focussed) control on a form

I have found some interesting solutions for this including iterating all controls and check for their focus state.

The ActiveControl property of the form class also seems to work rather well …

Lastest update in May 2011, inital post in May 2011

Allow a user to resize an Autosize form

Set a form to “autosize”  allows the form to shrink or grow by it’s contents. It however does not allow the user to resize the form manually.

To allow the user to resize the form set the form AutoSize property to false in the form onLoad event handler. This  allows the form resize initially but user resizable afterwards.

Of course changing the contents of the hosted controls may require you to resize the form. You can set the AutoSize  to true before making the changes or use the GetPreferredSize method and resize the form yourself.

Lastest update in May 2011, inital post in May 2011

Enabling keyboard input on Forms

By default forms do not get keyboard input.

To allow keyboard input set the forms  KeyPreview property to true.

This will enable the firing of the  KeyDown and  KeyUp events.

Lastest update in May 2011, inital post in May 2011