picture1为容器
Dim old_picX As Single
Dim old_picY As Single
Private Sub Picture1_DragDrop(Source As Control, X As Single, Y As Single)
If TypeOf Source Is PictureBox Then
Source.Move (X - old_picX), (Y - old_picY)
End If
End Sub
Private Sub Picture2_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
old_picX = X
old_picY = Y
Picture2.Drag vbBeginDrag
End Sub
Private Sub Picture2_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
Picture2.Drag vbEndDrag
End Sub
模块中
Public Sub picSelMoveDown(ByVal vobject As picturebox, Button As Integer, Shift As Integer, x As Single, y As Single)
If Button = 1 Then
isMove = True
bX = x
bY = y
End If
If Button = 1 And vobject.MousePointer = 8 Then
bX = x
bY = y
bW = vobject.Width
bH = vobject.Height
End If
End Sub
Public Sub picSelMoveIn(ByVal vobject As picturebox, Button As Integer, Shift As Integer, x As Single, y As Single)
If Button = 1 And isMove And vobject.MousePointer = 0 Then
vobject.Move x + vobject.Left - bX, y + vobject.Top - bY
End If
If Button = 0 Then
If x > vobject.Width - 150 And x < vobject.Width + 50 And y > vobject.Height - 150 And y < vobject.Height + 50 Then
vobject.MousePointer = 8
Else
vobject.MousePointer = 0
End If
ElseIf Button = 1 And vobject.MousePointer = 8 Then
If bW + x - bX <= 0 Or bH + y - bY <= 0 Then Exit Sub
vobject.Width = bW + x - bX
vobject.Height = bH + y - bY
End If
End Sub
Public Sub picSelMoveUp(ByVal vobject As picturebox, Button As Integer, Shift As Integer, x As Single, y As Single)
isMove = False
OTOP = vobject.Top
OLEFT = vobject.Left
OHEIGHT = vobject.Height
OWIDTH = vobject.Width
End Sub
窗体程序中
Private Sub pic2_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
Call picSelMoveDown(pic2, Button, Shift, x, y)
End Sub
Private Sub pic2_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
Call picSelMoveIn(pic2, Button, Shift, x, y)
End Sub
Private Sub pic2_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)
Call picSelMoveUp(pic2, Button, Shift, x, y)
End Sub