Here is some sample code. I used the detail sections MouseUp event to call
the subroutine in my test. You will obviously need to use some other method
to do this.
Public Sub MoveControls(MyBox As Rectangle, NewLeft As Double, NewTop As
Double)
Dim frm As Form
Dim OldTop As Double, OldLeft As Double
Dim OldRight As Double, OldBottom As Double
Dim ShiftTop As Double, ShiftLeft As Double
Dim ctrl As Control
Set frm = MyBox.Parent
OldTop = MyBox.Top
OldLeft = MyBox.Left
OldBottom = OldTop + MyBox.Height
OldRight = OldLeft + MyBox.Width
frm.InsideWidth = fnMax(frm.InsideWidth, NewLeft + (OldRight - OldLeft))
frm.InsideHeight = fnMax(frm.InsideHeight, NewTop + (OldBottom - OldTop))
MyBox.Top = NewTop
MyBox.Left = NewLeft
ShiftTop = NewTop - OldTop
ShiftLeft = NewLeft - OldLeft
For Each ctrl In frm.Controls
If ctrl.Left >= OldLeft And ctrl.Left <= OldRight And _
ctrl.Top >= OldTop And ctrl.Top <= OldBottom Then
ctrl.Top = ctrl.Top + ShiftTop
ctrl.Left = ctrl.Left + ShiftLeft
End If
Next
End Function
----
HTH
Dale
Dale Fye said:
Another option would be to add a rectangle to your form, set it's visible
property to False and send it to back. Put your other controls over it, like
you would have with a frame.
Then, create a subroutine which you pass the name of the rectangle, and the
new top and left positions.
Inside the subroutine, identify the rectangles initial top, left, height and
width positions, and loop through the controls to identify which controls
have a Top/Left position that is within the original rectangle. Then move
them to a new position that shifts their top and left coordinates based on
the difference in the rectangles original and new top/left positions.
-----
HTH
Dale
JohnM77 via AccessMonster.com said:
Thanks for your reply. I've about exhausted my googling for info on this one.
It seems that the contained controls do not move with the tab control, and
therefore the tab control serves no purpose for this particular use.
I could definitely see your method working well for a very ordered array of
controls, but since my controls are not in a perfectly orderly array, I'm
thinking the best method of positioning the controls is to code each control
individually.
Marshall Barton wrote:
I have a form on which I have a group of associated controls (textboxes,
comboboxes and checkboxes) that I wish to programmatically position. VB6 used
[quoted text clipped - 3 lines]
control would be suitable, but programmatically setting the top/left
properties does not change the tab control's position.
I don't remember the details, but I ran into several issues
when I trid to use a tab control for something similar. I
eventually gave up on the tab control idea and went back to
the old tried and true way of managing a group of controls.
Set the Tag property to something like G to identify the
controls in your "group". Then the code to reposition the
controls would be along these lines:
Dim ctl As Control
For Each ctl In Me.Comtrols
If ctl.Tag = "G" Then
ctl.Left = x
ctl.Top = y
End If
Next ctl
If the form has a lot of other controls that are not in the
"group", you should consider using the form's Open event to
initialize a modul level collection with just the controls
in the "group". Then the loop won't waste time going
through all the controls in the form or testing the Tag.