By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
428,631 Members | 826 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 428,631 IT Pros & Developers. It's quick & easy.

Adjust the heights and widths of multiple subforms without additional controls

P: n/a
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

Nov 13 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a
Hi Lauren,

I had some problems getting the code to work:
- Looks like the greater than signs didn't come through in the post. I
threw some in.
- I found that the main form needs a Form Header section. You could
test for that to make it flexible.

I haven't spent time to look at the code in detail, but here are some
observations:
- Pretty cool!
- The cursor doesn't change back to regular when you're done adjusting.
You'd probably need to call the MouseMove in the subforms to do that?
Could set that at runtime.
- It does take quite a lot of processor time while you're dragging.
Display the performance tab of the Task Manager while you're doing it.
- My border between Child2 and Child3 jumped to like .5 inch and stayed
that way. (Of course, I was throwing >'s around with abandon).

Jerry

Nov 13 '05 #2

P: n/a
Bummer the ">" signs somehow got convetred to "-" in the post.

Nov 13 '05 #3

P: n/a
lauren quantrell wrote:
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.


Thank you very much for this. I'll be trying it soon.
--
Tim http://www.ucs.mun.ca/~tmarshal/
^o<
/#) "Burp-beep, burp-beep, burp-beep?" - Quaker Jake
/^^ "Whatcha doin?" - Ditto "TIM-MAY!!" - Me
Nov 13 '05 #4

P: n/a
Tim,
Not that some of the ">" signs got switched to "-" during the post in
the If Than statements

Nov 13 '05 #5

P: n/a
Jerry,
I'm not sure but since the subforms are loaded with (ADO) recordsets it
looks like the subforms are requerying as they are being resized, which
might explain the 100% CPU usage during resize. My first thought...
lq

Nov 13 '05 #6

P: n/a
I've experienced this with MouseMove and read about it in other posts.
Every time the mouse moves a pixel, the code runs. And your code is
fairly complex.

Nov 13 '05 #7

P: n/a
Jerry,
Yes, the form has a FormHeader and in the subforms I put OnMouseMove to
set the screen.cursor back to "0."
Also on FormDeactivate I set the screen.cursor back to "0". I forgot to
mention that.
I leave a .5" space between Child2 and Child3 because I have labels in
there. You can adjust that to fit your needs.
lq

Nov 13 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.