Contents
Resize Sample Help

Sample Description: Resize

Points of Interest

Changing the Size of a Form

Automatically Resizing Controls on a Form

Setting a Control's Background Color

Control

Form

Image

For Help on Help, Press F1


Resize

A Resize event occurs in a form any time the size of the form changes. The change can result from a user moving one of the form's borders or when program code modifies the value of one of the form's size properties.

The most common use of this event is to reposition and/or resize the form's controls. Suppose your form has a button placed in the center of the form. The user now resizes the form by dragging one of the edges. In Form_Resize, you can place code that calculates the new center of the form and repositions the button accordingly.

The sample Resize form contains (12) image controls. There are three rows of four image controls that are all of equal size. The Form's Resize event executes a Resize method on the form, which resets the location and size of the twelve Image controls.


Automatically Resizing Controls on a Form

The following program code is associated with the form's Resize event.

Sub Resize()

  Dim control_width As Integer

  Dim control_height As Integer

  control_width = ResizeMasterForm.ScaleWidth / 4

  control_height = ResizeMasterForm.ScaleHeight / 3

  Image1.Move(0, 0, control_width, control_height)

  Image2.Move(control_width, 0, control_width, control_height)

  Image3.Move(control_width * 2, 0, control_width, control_height)

  Image4.Move(control_width * 3, 0, control_width, control_height)

  Image5.Move(0, control_height, control_width, control_height)

  Image6.Move(control_width, control_height, control_width, control_height)

  Image7.Move(control_width * 2, control_height, control_width, control_height)

  Image8.Move(control_width * 3, control_height, control_width, control_height)

  Image9.Move(0, control_height * 2, control_width, control_height)

  Image10.Move(control_width, control_height * 2, control_width, control_height)

  Image11.Move(control_width * 2, control_height * 2, control_width, control_height)

  Image12.Move(control_width * 3, control_height * 2, control_width, control_height)

End Sub

When the form's height or width are changed, either by the user or by program code, the method shown above is executed automatically. The variables control_width and control_height are used to compute the width and height of each control according to the size of the form.

The Image control's Move method is the most efficient way to change the size and location of each control. You could change the size and location by setting the Width, Height, Left, and Top properties, however, with the Move method these can be set in a single instruction.


Setting a Control's Background Color

To help see the difference between each of the controls, the BorderWidth and BorderOutset properties of each Image control has been set. In addition, each Image control's BackColor property has been set to a different color.

This may be done by directly entering a known RGB value into each of the BackColor properties, or by double-clicking on the BackColor property and selecting a color value from the Color dialog that is posted.


Changing the Size of a Form

To run the sample, simply place the mouse cursor next to one of the form's edges or corners. The mouse cursor will change to some type of directional sizing arrow. Now click and drag the mouse to resize the form.

As the size of the form changes, the size and location of all the Image controls are automatically updated. Each individual control's height and width should be proportionate to the height and width of the form.