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