-
Form - Minimum Size
I am using docking and anchoring etc to allow the user to resize a data entry form at run time. I have set the minimum size at form load from the size of the form at that time so that the user cant resize it less than the size at load. However this works fine if the form is not an MDI child.
Once I set it as an MDI Child, it seems to ignore the Minimum size properties I have set and the user can resize it to a tiny little form with just a title bar. I have tried putting code in the Resize event but just causes so much flicker that its unworkable - have I overlooked something -does minimumsize not apply to MDI Child FOrms ??
any help would be appreciated
thanks BH
-
This is a confirmed bug in the framework. Microsoft referes to SubClassing as aworkaround.... example:
Code:
Private Const WM_GETMINMAXINFO = &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 = m.GetLParam(GetType(MINMAXINFO))
mmi.ptMinTrackSize.x = Me.MinimumSize.Width
mmi.ptMinTrackSize.y = Me.MinimumSize.Height
mmi.ptMaxTrackSize.x = Me.MaximumSize.Width
mmi.ptMaxTrackSize.y = Me.MaximumSize.Height
System.Runtime.InteropServices.Marshal.StructureToPtr(mmi, m.LParam, True)
End Select
End If
MyBase.WndProc(m)
End Sub
Theres an easier way around if I remeber correctly, but I have that code at work, so I'll post that tomorrow if someone does not do it befor me.
/Leyan
-
Using the layout event is possible too. Heres an example for the MinimumSize:
Code:
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
/Leyan
-
minimum size of form
Thanks Athley, This works OK - I did achieve something similar using the resize event. Is there any way you know to stop the flicker when the user is trying toresize smaller than the minimum size.
regards
BH