Welcome to WindowsClient.net | Sign in | Join

Here are some frequently asked questions about Windows Forms and their answers.

Windows Forms FAQs

How do I constrain the size of MDI child forms since MinimumSize and MaximumSize properties don't seem to work?

It appears that this behavior is a bug that will be corrected in a future .NET release.

You can control the size of your child form by adding a Layout event handler for it. Here is a code snippet that imposes the minimum size that you set in its properties. You can also handle it by overriding the form's WndProc method as explained in

FIX: MinimumSize and MaximumSize Properties Are Not Obeyed When Window Is an MDI Child (Article ID: 327824)

[C#]

private void Document_Layout( object sender, LayoutEventArgs e ) 
{ 
  if ( Bounds.Width < MinimumSize.Width ) 
    Size = new Size( MinimumSize.WidthSize.Height ); 
  if ( Bounds.Height < MinimumSize.Height ) 
    Size = new Size( Size.Width, MinimumSize.Height ); 
} 

[Visual Basic]

Private Sub Document_Layout(ByVal sender As System.Object, _
    ByVal e As LayoutEventArgs) Handles MyBase.Layout 
  If (Bounds.Width < MinimumSize.Width) Then 
    Size = New Size(MinimumSize.Width, Size.Height) 
  End If 
  If (Bounds.Height < MinimumSize.Height) Then 
    Size = New Size(Size.Width, MinimumSize.Height) 
  End If 
End Sub

Contributed from George Shepherd's Windows Forms FAQ



Page view counter