Dynamically arrange controls on a form

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
 
A

Allen Browne

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top