vb 控件坐标计算问题 帮看下
来源:百度知道 编辑:UC知道 时间:2024/06/27 15:23:08
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