A while back I got a requirement for the client to be able to adjust
the relative heights of two subforms by click-dragging the mouse and I
came up with a kludge solution using a border control between the two
subforms. But I put my mind to this again recently and came up with a
solution (code below) that works well with multiple subforms to size
both the heights and widths of the sunforms relative to each other, and
it uses no additional controls.
I throw this code out in case others have the same needs and also in
the hopes someone will see some ways to improve it.
lq
To use this code:
Create a form. On the main form place a subform named Child1 on the
left side of the main form so that it takes up the whole height of the
main form but only half the width. On the right side of the main form
place a subform named Child2 so that its top lines up with Child1 and
takes up the remaining width of the main form to the right of Child1.
Then place a subform named Child3 under Child2 so that it takes up the
remainign space on the main form. What you have is a main form divided
into two columns, with three subforms. In the left column Child1 takes
up the whole height of the main form and in the right column, the
height is equally divided between Child2 and Child3.
When you click the left mouse button and drag in the spaces between the
subforms you'll be able to adjust the position of the vertical column
that seperates Child1 from Child2 and Child3, as well as adjust the
heights of Child2 and Child3
'Declarations:
Private isSizingVert As Boolean
Private isSizingHorz As Boolean
Private Sub Detail_MouseMove(Button As Integer, Shift As Integer, x As
Single, Y As Single)
On Error GoTo myErr
Dim c2Bot As Long, c1Rt As Long
'resize verical
c2Bot = Me.Child2.Top + Me.Child2.Height
If Y c2Bot - 100 And Y < c2Bot + 100 And x Me.Child2.Left Then
Screen.MousePointer = 7
isSizingVert = True
Else
Screen.MousePointer = 0
If Button < 1 Then isSizingVert = False
End If
If Button = 1 And isSizingVert = True Then
Screen.MousePointer = 7
isSizingVert = True
If Y Me.Child2.Top + 725 And Y < (Me.InsideHeight +
Me.FormHeader.Height) - 2000 Then
Me.Child2.Height = Y - Me.Child2.Top
Me.Child3.Height = (Me.Child1.Height + Me.Child1.Top) - (Y
+ 575)
Me.Child3.Top = Y + 575
End If
End If
'resize horizontal
c1Rt = Me.Child1.Left + Me.Child1.Width
If x c1Rt - 100 And x < c1Rt + 100 And x < Me.InsideWidth * 0.7
And Y Me.Child1.Top Then
Screen.MousePointer = 9
isSizingHorz = True
Else
If Screen.MousePointer < 7 Then
Screen.MousePointer = 0
If Button < 1 Then isSizingHorz = False
End If
End If
If Button = 1 And isSizingHorz = True Then
isSizingHorz = True
If x Me.Child1.Left + 3000 And x < Me.InsideWidth * 0.7
Then
Me.Child1.Width = x - Me.Child1.Left
Me.Child2.Width = Me.InsideWidth - (Me.Child1.Width +
225)
Me.Child2.Left = x + 100
Me.Child3.Width = Me.Child2.Width
Me.Child3.Left = Me.Child2.Left
End If
End If
myExit:
Exit Sub
myErr:
MsgBox Err.Number & " - " & Err.Description
Resume myExit
End Sub