Dynamically arrange controls on a form

  • Thread starter Thread starter Kevin C Niven
  • Start date Start date
K

Kevin C Niven

I have a form that shows or hides various controls based on the
settings of a cbo box.

When a number of these boxes disappear, it would be nice to shore up
the form, so there isn't a bunch of blank spaces in the middle.

This involves moving a bunch of controls using their Top properties
(not necessarily their Left props).

It would be nice to simply move them all up (i.e., change their Top
values) -1000 twips, without having to worry about what their precise
Top values are upon Load. This way I can manually rearrange the
position of the controls without having to change their initial Top
values in the VB code.

What is the best way to do that, if any?

Thanks,
Kevin
 
You can set the Top property of a text box, e.g.:

Dim ctl As Control
Const lngcY = 1000

For Each ctl in Me.Controls
If .Top > lngcY Then
.Top = .Top - lngcY
End If
Next

You will need something more than that if you have controls that contain
other controls, such as a tab control or option group.
 
Back
Top