vb 控件坐标计算问题 帮看下

来源:百度知道 编辑:UC知道 时间:2024/06/27 15:23:08
我现在要实现控件拖拽 已知 一个panel控件 2个picturebox picturebox1为目标控件 picturebox2为拖拽控件 现在我要实现拖动picturebox2移动到(picture2的中心点) 松开鼠标时 判断picturebox2的中心点是否在picturebox1的区域范围内 如果是 则将picturebox2与picturebox1重合(将坐标相同) 谁告诉我下 可以追加分

Dim ox As Single, oy As Single
Private Sub Picture2_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
ox = X: oy = Y
Picture2.ZOrder 0
End Sub
Private Sub Picture2_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 1 Then Picture2.Move Picture2.Left + X - ox, Picture2.Top + Y - oy
End Sub
Private Sub Picture2_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
lx = Picture1.Left - Picture2.Width / 2
rx = Picture1.Left + Picture1.Width - Picture2.Width / 2
ty = Picture1.Top - Picture2.Height / 2
By = Picture1.Top + Picture1.Height - Picture2.Height / 2
If Picture2.Left > lx And Picture2.Left < rx And Picture2.Top > ty And Picture2.Top < By Then Picture2.Move Picture1.Left, Picture1.Top
End Sub