Windows Forms Layout
FAQ Home
1.
How can I programmatically set the initial position of a Form so that it is
displayed properly after calling ShowDialog()?
2. How do I create a custom layout engine?
3. I have a form with several controls on it. As I size the
form, the controls are being resized continuously. Is it possible to
postpone changing the controls position until the resizing is complete?
1 How can I programmatically set the initial position of
a Form so that it is displayed properly after calling ShowDialog()?
In addition to setting the Location property of the form, make sure you also
set the StartPosition property of the form to
FormStartPosition.Manual.
2 How do I create a custom layout engine?
Chris Anderson discusses how to implement a custom layout engine and gives
sample code in an article on
gotnetdot.com.
3 I have a form with several controls on it. As I size
the form, the controls are being resized continuously. Is it possible to
postpone changing the controls position until the resizing is complete?
Shawn Burke suggested this solution in a response on the
microsoft.public.dotnet.framework.windowsforms newsgroup. The idea is to do
the painting on Idle. This means you simple invalidate when being sized and
then do your full paint when the size completes. Here is the code that you
would add to your form.
bool idleHooked = false;
protected override void OnResize(EventArgs e)
{
if (!idleHooked)
{
Application.Idle += new EventHandler(OnIdle);
}
}
private void OnIdle(object s, EventArgs e)
{
Invalidate();
PerformLayout();
if (idleHooked)
{
Application.Idle -= new EventHandler(OnIdle);
}
}
|