In an MDI application, the MDI child’s MaximumSize and MinimumSize properties don’t seem to take effect. How can I restrict the size of my MDI child?

Platform: WinForms| Category: MDI

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 this Microsoft KB article.

[C#]
	private void Document_Layout(object sender, System.Windows.Forms.LayoutEventArgs e)
	{
		if(this.Bounds.Width < this.MinimumSize.Width)
			this.Size = new Size(this.MinimumSize.Width, this.Size.Height);

		if(this.Bounds.Height < this.MinimumSize.Height)
			this.Size = new Size(this.Size.Width, this.MinimumSize.Height);
	}

[VB.NET]
	Private Sub Document_Layout(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LayoutEventArgs) Handles MyBase.Layout

		If (Me.Bounds.Width < Me.MinimumSize.Width) Then
			Me.Size = New Size(Me.MinimumSize.Width, Me.Size.Height)
		End If

		If (Me.Bounds.Height < Me.MinimumSize.Height) Then
			Me.Size = New Size(Me.Size.Width, Me.MinimumSize.Height)
		End If
	End Sub

Share with

Related FAQs

Couldn't find the FAQs you're looking for?

Please submit your question and answer.