OldHeight, OldWidth 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.

Description

Returns the previous height or width, in points, of the control.

Syntax

object.OldHeight

object.OldWidth

The OldHeight and OldWidth property syntaxes have these parts:

Part

Description

object

Required. A valid object.


Remarks

OldHeight and OldWidth are read-only.

The OldHeight and OldWidth properties are automatically updated when you move or size a control. If you change the size of a control, the Height and Width properties store the new height and OldHeight and OldWidth store the previous height.

These properties are valid only in the Layout event.

See Also

Height, Width properties, Layout event, LayoutEffect property, OldLeft, OldTop properties.

Example

The following example uses the OldLeft, OldTop, OldHeight, and OldWidth properties within the Layout event to keep a control at its current position and size. The user clicks the CommandButton labeled Move ComboBox to move the control, and then responds to a message box. The user can click the CommandButton labeled Reset ComboBox to reset the control for another repetition.

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

  • Two CommandButton controls named CommandButton1 and CommandButton2.
  • A ComboBox named ComboBox1.
    Dim Initialize As Integer
    Dim ComboLeft, ComboTop, ComboWidth, ComboHeight As Integer
    
    Private Sub UserForm_Initialize()
        Initialize = 0
        CommandButton1.Caption = "Move ComboBox"
        CommandButton2.Caption = "Reset ComboBox"
        
        'Information for resetting ComboBox
        ComboLeft = ComboBox1.Left
        ComboTop = ComboBox1.Top
        ComboWidth = ComboBox1.Width
        ComboHeight = ComboBox1.Height
    End Sub
    
    Private Sub CommandButton1_Click()
            ComboBox1.Move 0, 0, , , True
    End Sub
    
    Private Sub UserForm_Layout()
        Dim MyControl As Control
        Dim MsgBoxResult As Integer
        
        If Initialize = 0 Then   'Suppress MsgBox on initial layout event.
            Initialize = 1
            Exit Sub
        End If
        
        MsgBoxResult = MsgBox("In Layout event - Continue move?", vbYesNo)
        If MsgBoxResult = vbNo Then
            ComboBox1.Move ComboBox1.OldLeft, ComboBox1.OldTop, ComboBox1. _
    OldWidth, ComboBox1.OldHeight End If End Sub Private Sub CommandButton2_Click() ComboBox1.Move ComboLeft, ComboTop, ComboWidth, ComboHeight 'OldLeft, OldTop, OldWidth, and OldHeight are not recognized here. 'The following statement, if not commented, would produce an error
    'at run time. 'ComboBox1.Move ComboBox1.OldLeft, ComboBox1.OldTop, ComboBox1.
    'OldWidth, ComboBox1.OldHeight End Sub