# Re: 为何我用程式码来作表单的拖曳可是无法得到预期的效果，为什么呢？？？

Posted by 笑儿 on August 13, 1998 at 18:40:13:

In Reply to: 为何我用程式码来作表单的拖曳可是无法得到预期的效果，为什么呢？？？ posted by jordan on August 13, 1998 at 12:58:11:

因为每一个X,Y都是相对于表单而言, 而设定Left,Right属性是相对于系统而言, 请你把X,Y改成用GetCursorPos取得的座标好吗

: Dim qx,qy,wx,wy

: Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
: qx = X: qy = Y
: End Sub

: Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
: If Button = 1 Then
: wx = wx - (qx - X)
: wy = wy - (qy - Y)
: End If
: End Sub

: Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
: If Button = 1 Then
: Form1.Left = wx
: Form1.Top = wy
: End If
: End Sub

Follow Ups: