7,763
社区成员
发帖
与我相关
我的任务
分享
Option Explicit
Private msMinX As Single
Private msMinY As Single
Private msFcx As Single
Private msFcy As Single
Private Sub Form_Load()
msMinX = P1.ScaleWidth - P2.Width
msMinY = P1.ScaleHeight - P2.Height
End Sub
Private Sub P2_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If (1 = Button) Then
msFcx = X
msFcy = Y
End If
End Sub
Private Sub P2_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim cx As Single, cy As Single
If (1 = Button) Then
cx = X + P2.Left - msFcx
cy = Y + P2.Top - msFcy
If (0 < cx) Then
cx = 0: msFcx = X - P2.Left
Else
If (cx < msMinX) Then cx = msMinX: msFcx = X
End If
If (0 < cy) Then
cy = 0: msFcy = Y - P2.Top
Else
If (cy < msMinY) Then cy = msMinY: msFcy = Y
End If
Call P2.Move(cx, cy)
End If
End Sub
Private Sub P2_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim cx As Single, cy As Single
If (1 = Button) Then
cx = X + P2.Left - msFcx
cy = Y + P2.Top - msFcy
If (0 > cx) Then
cx = 0: msFcx = X
Else
If (cx > msMaxX) Then cx = msMaxX: msFcx = X
End If
If (0 > cy) Then
cy = 0: msFcy = Y
Else
If (cy > msMaxY) Then cy = msMaxY: msFcy = Y
End If
Call P2.Move(cx, cy)
End If
End Sub
Option Explicit
Private msMaxX As Single
Private msMaxY As Single
Private msMcx As Single
Private msMcy As Single
Private msFcx As Single
Private msFcy As Single
Private Sub Form_Load()
msMaxX = P1.ScaleWidth - P2.Width
msMaxY = P1.ScaleHeight - P2.Height
End Sub
Private Sub P2_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If (1 = Button) Then
msMcx = X
msMcy = Y
msFcx = X
msFcy = Y
End If
End Sub
Private Sub P2_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim cx As Single, cy As Single
If (1 = Button) Then
cx = X + P2.Left - msFcx
cy = Y + P2.Top - msFcy
If (0 > cx) Then
cx = 0: msFcx = X - P2.Left
Else
If (cx > msMaxX) Then cx = msMaxX: msFcx = X
End If
If (0 > cy) Then
cy = 0: msFcy = Y - P2.Top
Else
If (cy > msMaxY) Then cy = msMaxY: msFcy = Y
End If
Call P2.Move(cx, cy)
End If
End Sub