First, about form1
'在窗体上设置几个PictureBox控件 把要拖动的对象的DragMode设置成1-automatic(0-Manual)
Private Sub Form_DragDrop(Source As Control,X As Single,y As Single)
form1.picture=source.picture
End sub
Private sub picture3_dragdrop(source as control,x as single,y as single)
debug.print typeof source
if typeof source is pictruebox then
picture3.picture=source.picture
end if
end sub
''''''''''''''如果想要移动控件 用 MOVE 方法即可
dim tx as single
dim ty as single
Private Sub Control_mousedown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = vbLeftButton Then
tX = X
tY = Y
End If
End Sub
Private Sub control_mousemove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = vbLeftButton Then
If Abs(X - tX) > 105 Or Abs(Y - tY) > 105 Then
control.Move control.Left + X - tX, control.Top + Y - tY
End If
End If
End Sub
Dim tx As Single
Dim ty As Single
Private Sub Control_mousedown(Button As Integer, Shift As Integer, X As Single, Y As Single)
'x,y是鼠标移动到的位置
If Button = vbLeftButton Then
tx = X
ty = Y
Debug.Print tx, ty
End If
End Sub
Private Sub control_mousemove(Button As Integer, Shift As Integer, X As _
Single, Y As Single)
If Button = vbLeftButton Then
If Abs(X - tx) > 500 Or Abs(Y - ty) > 500 Then
Debug.Print X, tx, control.Left
Debug.Print Y, ty, control.Top
control.Move control.Left + X - tx, control.Top + Y - ty
Debug.Print , , control.Left, control.Top
End If
End If
End Sub
Private Sub control_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
Debug.Print X, Y 'x,y是相对的坐标
End Sub
Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
Form1.PSet (X, Y), RGB(255, 0, 0)
End Sub
Dim oldX As Single, oldY As Single
Private Sub Form_DragDrop(Source As Control, X As Single, Y As Single)
Source.Move Left + X - oldX, Top + Y - oldY
End Sub
Private Sub Frame1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
oldX = X + Left
oldY = Y + Top
Frame1.Drag 1
End Sub
Private Sub Frame1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
'在控件的 MouseDown 里记下鼠标位置(mX,mY),在MouseMove里写:
If Button = vbLeftButton Then
' Frame1.Move Frame1.Left + X - oldX, Frame1.Top + Y - oldX
End If
End Sub
利用上面这段代码可是实现frame1在form1上的拖动,但是,如果我再在窗体上加上一个frame2或其他的控件,这样我拖动frame1到frame2的时候,就不会出现我想要的结果,就是frame1停在frame2上,而是跳到了一个不知道的什么地方。
各位给各解决办法。
Private Sub Text1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Text1.Drag vbBeginDrag
End Sub
Private Sub Text1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
Text1.Drag vbEndDrag
End Sub
Private Sub Command1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Command1.Drag vbBeginDrag
End Sub
Private Sub Command1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
Command1.Drag vbEndDrag
End Sub
Private Sub Form_DragDrop(Source As control, X As Single, Y As Single)
Source.Move X - Source.Width / 2, Y - Source.Height / 2
End Sub