Public Sub DragControl(ByRef oControl As Object, ByVal Button As Integer, ByVal X As Single, ByVal Y As Single, Optional ByVal bInit As Boolean, Optional ByVal bMoveable As Boolean, Optional ByVal bResizable As Boolean)
Static lXoff As Single, lYoff As Single, bSizing As Boolean
Dim bBoth As Boolean, bSized As Boolean
If bInit Then
If (Y > (oControl.Height - 150) Or X > (oControl.Width - 150)) And bResizable Then
bSizing = True
End If
lXoff = X
lYoff = Y
Exit Sub
End If
If bResizable Then
bBoth = True
If Y > (oControl.Height - 150) Then
oControl.MousePointer = vbSizeNS
Else
bBoth = False
End If
If X > (oControl.Width - 150) Then
oControl.MousePointer = IIf(bBoth, vbSizeNWSE, vbSizeWE)
Else
If Not bBoth Then oControl.MousePointer = vbDefault
End If
End If
If bResizable And bSizing Then
If Button = vbLeftButton Then
If (Y > (oControl.Height - 150) Or X > (oControl.Width - 150)) Then
bBoth = True
If Y > (oControl.Height - 150) Then
oControl.MousePointer = vbSizeNS
If Button = vbLeftButton Then
oControl.Height = oControl.Height + Y - lYoff
lYoff = oControl.Height
lXoff = oControl.Width
bSized = True
End If
Else
bBoth = False
End If
If X > (oControl.Width - 150) Then
oControl.MousePointer = IIf(bBoth, vbSizeNWSE, vbSizeWE)
If Button = vbLeftButton Then
oControl.Width = oControl.Width + X - lXoff
lYoff = oControl.Height
lXoff = oControl.Width
bSized = True
End If
End If
End If
Else
oControl.MousePointer = vbDefault
bSizing = False
End If
End If
If Not bSized And bMoveable And Not bSizing Then
If Button = vbLeftButton Then oControl.Move oControl.Left + X - lXoff, oControl.Top + Y - lYoff
End If
End Sub
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
DragControl Form1, Button, X, Y, True, True, True
End Sub
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
DragControl Form1, Button, X, Y, False, True, True
End Sub