Height, Width Properties

Applies To

CheckBox control, ComboBox control, CommandButton control, Image control, Label control, ListBox control, MultiPage control, OptionButton control, ScrollBar control, SpinButton control, TabStrip control, TextBox control, ToggleButton control, UserForm object.

Description

The height or width, in points, of an object.

Syntax

object.Height [= Single]

object.Width [= Single]

The Height and Width property syntaxes have these parts:

Part

Description

object

Required. A valid object.

Single

Optional. A numeric expression specifying the dimensions of an object.


Remarks

The Height and Width properties are automatically updated when you move or size a control. If you change the size of a control, the Height or Width property stores the new height or width and the OldHeight or OldWidth property stores the previous height or width. If you specify a setting for the Left or Top property that is less than zero, that value will be used to calculate the height or width of the control, but a portion of the control will not be visible on the form.

If you move a control from one part of a form to another, the setting of Height or Width only changes if you size the control as you move it. The settings of the control's Left and Top properties will change to reflect the control's new position relative to the edges of the form that contains it.

The value assigned to Height or Width must be greater than or equal to zero. For most systems, the recommended range of values is from 0 to +32,767. Higher values may also work depending on your system configuration.

See Also

InsideHeight, InsideWidth properties, Left, Top properties.

Example

The following example sets the dimensions of an Image to the size of a TabStrip's client area when the user clicks a CommandButton. This code sample uses the following properties: Height, Left, Top, Width, ClientHeight, ClientLeft, ClientTop, and ClientWidth.

To use this example, copy this sample code to the Declarations portion of a form. Make sure that the form contains:

  • A CommandButton named CommandButton1.
  • A TabStrip named TabStrip1.
  • An Image named Image1.
    Private Sub UserForm_Initialize()
        CommandButton1.Caption = "Size Image to Tab Area"
        CommandButton1.WordWrap = True
        CommandButton1.AutoSize = True
    End Sub
    
    Private Sub CommandButton1_Click()
        Image1.ZOrder (fmFront)             'Place Image in front of TabStrip
    
        'ClientLeft and ClientTop are measured from the edge of the TabStrip, 
        'not from the edges of the form containing the TabStrip.
        Image1.Left = TabStrip1.Left + TabStrip1.ClientLeft
        Image1.Top = TabStrip1.Top + TabStrip1.ClientTop
        Image1.Width = TabStrip1.ClientWidth
        Image1.Height = TabStrip1.ClientHeight
    
    End Sub