FIX: MinimumSize and MaximumSize properties are not obeyed when window is an MDI child (327824)
The information in this article applies to:
- Microsoft .NET Framework 1.0
- Microsoft Visual Basic .NET (2002)
- Microsoft Visual C# .NET (2002)
This article was previously published under Q327824 SYMPTOMS The size of a Multiple Document Interface (MDI) child form
is not constrained by MinimumSize and MaximumSize properties at run time, although the boundaries are respected at
design time. WORKAROUND To work around this problem, you can paste the following
sample code in the Form class of your MDI child. This code intercepts the GetMinMaxInfo window message, tells the message what the MinimumSize and MaixmumSize properties are, and then passes the edited message along:
Visual Basic .NET
Private Const WM_GETMINMAXINFO As Integer = &H24
Private Structure POINTAPI
Dim x As Integer
Dim y As Integer
End Structure
Private Structure MINMAXINFO
Dim ptReserved As POINTAPI
Dim ptMaxSize As POINTAPI
Dim ptMaxPosition As POINTAPI
Dim ptMinTrackSize As POINTAPI
Dim ptMaxTrackSize As POINTAPI
End Structure
Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
If Me.IsMdiChild Then
Select Case m.Msg
Case WM_GETMINMAXINFO
Dim mmi As MINMAXINFO = CType(m.GetLParam(GetType(MINMAXINFO)), MINMAXINFO)
mmi.ptMinTrackSize.x = Me.MinimumSize.Width
mmi.ptMinTrackSize.y = Me.MinimumSize.Height
If Not (Me.MaximumSize.Width = 0 And Me.MaximumSize.Height = 0) Then
mmi.ptMaxTrackSize.x = Me.MaximumSize.Width
mmi.ptMaxTrackSize.y = Me.MaximumSize.Height
End If
System.Runtime.InteropServices.Marshal.StructureToPtr(mmi, m.LParam, True)
End Select
End If
MyBase.WndProc(m)
End Sub
Visual C# .NET
private const long WM_GETMINMAXINFO = 0x24;
public struct POINTAPI
{
public int x;
public int y;
}
public struct MINMAXINFO
{
public POINTAPI ptReserved;
public POINTAPI ptMaxSize;
public POINTAPI ptMaxPosition;
public POINTAPI ptMinTrackSize;
public POINTAPI ptMaxTrackSize;
}
protected override void WndProc(ref System.Windows.Forms.Message m )
{
if (this.IsMdiChild)
{
if (m.Msg == WM_GETMINMAXINFO)
{
MINMAXINFO mmi = (MINMAXINFO)m.GetLParam(typeof(MINMAXINFO));
mmi.ptMinTrackSize.x = this.MinimumSize.Width;
mmi.ptMinTrackSize.y = this.MinimumSize.Height;
if (this.MaximumSize.Width != 0 || this.MaximumSize.Height != 0)
{
mmi.ptMaxTrackSize.x = this.MaximumSize.Width;
mmi.ptMaxTrackSize.y = this.MaximumSize.Height;
}
System.Runtime.InteropServices.Marshal.StructureToPtr(mmi, m.LParam, true);
}
}
base.WndProc(ref m);
}
STATUS This bug was corrected in .NET Framework,
Visual Basic .NET (2003), and Visual C# .NET (2003).
REFERENCESFor additional
information, click the article number below to view the article in the
Microsoft Knowledge Base: 185733 HOWTO: Limit a Window's Minimum and Maximum Size
Modification Type: | Minor | Last Reviewed: | 2/3/2006 |
---|
Keywords: | kbvs2005swept kbvs2005doesnotapply kbfix kbWindowsForms KB327824 |
---|
|