home account info subscribe login search My ITKnowledge FAQ/help site map contact us


 
Brief Full
 Advanced
      Search
 Search Tips
To access the contents, click the chapter and section titles.

Visual Basic 6 Programming Blue Book: The Most Complete, Hands-On Resource for Writing Programs with Microsoft Visual Basic 6!
(Publisher: The Coriolis Group)
Author(s): Peter G. Aitken
ISBN: 1576102815
Publication Date: 08/01/98

Bookmark It

Search this book:
 
Previous Table of Contents Next


Table 3.1 lists some other form properties you need to know about. Note that you can view information about any property by selecting it in the Property window and pressing F1.

Moving, Sizing, And Aligning Controls

Once you have placed controls on a form, you will probably need to tweak and fine-tune their sizes and positions. A sloppily constructed form—one with poorly aligned and inconsistently sized controls—will not impress your customers.

To work with controls on a form, you must select the control or controls that interest you. To select multiple controls, click on the first one, then press and hold the Shift key while you click on the others. As I mentioned previously, selected controls display handles on their edges. If only one control is selected, its handles are dark. If two or more controls are selected, the handles on each control are white—except for the last one that was selected, which has dark handles.


TIP:  Easy Deletions

To delete a control, select it and press Del. If you select multiple controls, you can delete them all at once.


When you have one control selected, you can change its size by pointing at one of its handles and dragging the outline to the desired size. As you drag, a small window displays the control’s size in twips. You can change the selected control’s position by pointing to the control (not a handle) and dragging. As you do so, a small window displays the position of the control within the form. As with control size, position is expressed in twips and gives you the horizontal and vertical distance between the control’s top left corner and the top left corner of the form.

Table 3.1 Some important properties of form objects.

Property name Description
BackColor The color of the form background, behind any controls.
BorderStyle Determines whether the form can be sized by the user and the type of border displayed around it.
Caption The text in the form’s title bar.
Font The typeface used for text displayed on the form. Does not affect text displayed in controls.
ForeColor The color used for text and graphical objects displayed on the form. Does not affect the color of controls.
MousePointer Determines the appearance of the mouse pointer when it is over the form.

With more than one control selected, you can move them as a group, allowing the individual controls to retain their positions relative to each other. You cannot, however, change the size of multiple selected controls.

Aligning Controls

Alignment of controls is an important design issue. The Visual Basic design grid greatly simplifies basic alignment tasks by displaying a grid of dots on the design form. Visual Basic’s normal behavior is to “snap” controls to this grid. In other words, when you are moving or sizing a control, its edges always align with the grid—they cannot take intermediate positions. By aligning controls to the grid, it is relatively simple to ensure that a group of controls are all the same size and are also equally spaced.

You can control the design grid using the Options dialog box, which you display by selecting Options from the Tools menu. In the dialog box, click on the General tab and look for the Form Grid Settings section. You have several options to set here:

  Show Grid determines whether the grid dots are displayed. Controls will snap to the grid whether or not the grid is displayed.
  Width and Height set the spacing of grid dots in twips.
  Align Controls to Grid specifies whether controls snap to the grid or are free to be positioned at any location.

Changing the width or height of the grid does not affect controls already on the form; only controls added after the grid has been modified will snap to the new settings. The same is true of turning alignment on or off.

A more powerful way to align controls is with the Align command on the Format menu. First, select two or more controls that you want to align by holding the Shift key down while clicking on the controls. Be sure to click last on the control you want the others to align with—it will display dark handles while the others will display white ones. Then select Align from the Format menu and choose the desired alignment. Here are the options:

  Tops, Middles, or Bottoms—The controls will be moved vertically so that the specified locations all align with the master control. Horizontal position does not change.
  Lefts, Centers, Rights—The controls will be moved horizontally so that the specified locations all align with the master control. Vertical position does not change.
  To Grid—The controls are all moved to align with the nearest grid location. This command is useful if you have placed controls with Snap to Grid turned off and now want them aligned with the grid.


TIP:  Multiples And Masters

After selecting multiple controls, you can change the “master” control (the one with the dark handles) by clicking another control in the group. To deselect the controls, click on any other object on the form (or the form itself).


Modifying Control Size And Spacing

Visual Basic also has a command that simplifies the task of making a group of controls all the same size. Select the controls, again making sure that the master control is the last selection. Then select Make Same Size from the Format menu and choose which dimension(s) to make the same as the master control. To make the size of the selected controls snap to the design grid, select Size to Grid from the Format menu.

Visual Basic also provides commands that simplify the task of setting the spacing between controls. You can work with vertical or horizontal spacing, as required. Start by selecting three or more controls, then select either Vertical Spacing or Horizontal Spacing from the Format menu. Regardless of the spacing you select, your choices are the same:

  Make Equal—Spacing between selected controls is made equal; the two controls that are farthest apart remain the same distance apart.
  Increase—The distance between controls is increased by a small amount; the leftmost or topmost control does not move.
  Decrease—The distance between controls is decreased by a small amount; the leftmost or topmost control does not move.
  Remove—Spacing between the controls is removed so their edges touch.


Previous Table of Contents Next


Products |  Contact Us |  About Us |  Privacy  |  Ad Info  |  Home

Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc.
All rights reserved. Reproduction whole or in part in any form or medium without express written permission of EarthWeb is prohibited. Read EarthWeb's privacy statement.