Visual Basic Concepts

Resizing Controls Dynamically

In a Visual Basic application, you can change the size and shape of a picture box, image control, or form at run time, just as you can change its position.

The following properties affect size.

Property Applies to Description
Align Picture boxes and Data controls If set to align a picture box to the top (1) or bottom (2) of a form, the width of the picture box always equals the width of the inside of the form. If set to align a picture box to the left (3) or the right (4) of a form, the height of the picture box is the height of the inside of the form.
Height All forms and all controls except timers, menus, and lines Height of the object expressed in the scale mode of the form (twips by default).
Width All forms and all controls except timers, menus, and lines Width of the object expressed in the scale mode of the form (twips by default).
AutoSize Labels and picture boxes If True, always causes Visual Basic to adjust the picture box dimensions to the size of the contents.
Stretch Image controls If True, the bitmap or metafile stretches to fit the size of the image control. If False, the size of the image control changes to match the size of the bitmap or metafile it contains.

In this example, a command button named cmdGrow grows larger each time the user clicks it:

Private Sub cmdGrow_Click ()
   cmdGrow.Height = cmdGrow.Height + 300
   cmdGrow.Width = cmdGrow.Width + 300
End Sub