VB拖放问题

来源:百度知道 编辑:UC知道 时间:2024/05/18 01:13:12
最近要交个作业,望大家帮帮忙,谢谢!
操作都是在窗体内完成的。窗体内有个控件(图片框),要求将控件拖动到该窗体的多个指定位置,拖放到一个指定位置后原控件保持不变(主要是原控件的位置不变),可以继续多次拖放。
希望能给出具体代码,谢谢!!
哦,忘了还有两点,控件拖到指定位置后能自动到达指定位置的中央(比如指定位置是一个Label框,控件能自动到这个框的中央),还有就是拖进去了以后还可以将它拖回原来的控件处 ,谢谢你们的回答

我用的是vb6,这个程序有个缺点就是移动的时候看不见控件~
建立一个picturebox(把它的index属性改为0)和两个shape(比picturebox大),不要重合
Dim w1%, w2%, h1%, h2%, m%, k%, l%
Private Sub Form_Load()
k = Picture1(0).Left
l = Picture1(0).Top
End Sub
Private Sub Picture1_MouseDown(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
If Index = 0 Then
w1 = X - Picture1(0).Left: w2 = Picture1(0).Left + Picture1(0).Width - X
h1 = Y - Picture1(0).Top: h2 = Picture1(0).Top + Picture1(0).Height - Y
Else

End If
End Sub
Private Sub Picture1_MouseUp(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
If Index = 0 Then
m = m + 1
If (X - w1 > Shape1.Left And X + w2 < Shape1.Left + Shape1.Width _
And Y - h1 > Shape1.Top And Y + h2 < Shape1.Top + Shape1.Height) Then
Load Picture1(m)
Picture1(m).Left = Shape1.Left + Shape1.Width / 2 - Picture1(m).Width / 2: