The ability to easily create complex and
attractive forms is one of Visual Basic’s strengths. Even so, the
task of positioning and sizing lots of controls into an efficient
and easy-to-use form layout can be rather time-consuming. By taking
advantage of VB6’s form layout tools, you can save a lot of
time.

The most basic of these tools is the align to
grid feature. By default, each VB form that you create displays a
grid of dots on it. All controls that you place on the form
automatically “snap” to this grid, both their position and size.
This makes it a lot easier to align controls and make them the same
size than if you had pixel-level control over their position and
size. Using the Options dialog box (select Tools | Options and then
click the General tab), you can control the size of the grid,
specify whether it’s displayed, and decide whether controls snap to
it.

You can find other layout tools in the Format
menu. Most of these tools require that you first select two or more
controls. You can do so either by dragging a box around the
controls or by clicking the controls while holding down the [Shift]
key. When you select multiple controls, you’ll notice that one of
them displays black handles, while the others display white
handles. VB uses the control with the black handles as the template
for subsequent layout commands. These commands are:

  • Format | Align: aligns all selected controls
    to the template control either vertically or horizontally.
  • Format | Make Same Size: makes all selected
    controls the same size (width, height, or both) as the template
    control.
  • Format | Horizontal Spacing: lets you change,
    remove, or equalize the horizontal spacing between the selected
    controls.
  • Format | Vertical Spacing: lets you change,
    remove, or equalize the vertical spacing between the selected
    controls.

Once you get the hang of these layout commands,
I think you’ll find that your form design goes a lot faster.

Advance your scripting skills to the next level with TechRepublic’s free Visual Basic newsletter, delivered each Friday. Automatically sign up today!