|
|
Title | Resize specific controls to take advantage of form size |
Keywords | resize, specific controls, form size |
Categories | Controls, Tips and Tricks |
|
|
In the Form_Resize event handler, resize specific controls that contain scrollable areas to take best advantage of the form's new size. For example, a ListBox, Grid, or TreeView control may be able to display more information when the form is enlarged.
Note that you do not need to arrange the controls if the form is minimized because the user cannot see the controls. Note also that the code should never try to give a control a width or height that is less than zero. I usually set minimum sizes at 120 twips.
|
|
' Make the controls fit.
Private Sub Form_Resize()
Const MARGIN As Single = 120
Dim wid As Single
Dim hgt As Single
' Don't bother if we're minimized.
If WindowState = vbMinimized Then Exit Sub
' See how wide we can make the name and address fields.
wid = ScaleWidth - MARGIN - txtName.Left
If wid < 120 Then wid = 120
txtName.Width = wid
txtStreet.Width = wid
txtCity.Width = wid
' See how big we can make the assignments list.
wid = ScaleWidth - 2 * MARGIN
If wid < 120 Then wid = 120
hgt = ScaleHeight - MARGIN - lstAssignments.Top
If hgt < 120 Then hgt = 120
lstAssignments.Move _
lstAssignments.Left, lstAssignments.Top, _
wid, hgt
End Sub
|
|
|
|
|
|