Option Explicit
Private Type Position
Left As Single
Top As Single
End Type
Private Sub UserForm_Layout()
Static Pos As Position
Dim Mvd As Boolean
'If the form is just being initialized, store the position
If Pos.Left = 0 Or Pos.Top = 0 Then
Pos.Left = Me.Left
Pos.Top = Me.Top
Exit Sub
End If
'Check to see if the form has been moved
Mvd = False
If Me.Left <> Pos.Left Then
Me.Left = Pos.Left
Mvd = True
End If
If Me.Top <> Pos.Top Then
Me.Top = Pos.Top
Mvd = True
End If
If Mvd Then
MsgBox "Please don't move me !", vbCritical
End If
End Sub
کامنت