开发者

In Visual Basic how would I move the location of a form to that of the pointer when it is clicked?

I tried to use the code:

Private Sub SpaceInvadersControlButton_MouseDown (ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles SpaceInvadersControlButton.MouseDown
     If e.Button = Windows.Forms.MouseButtons.Right then
         Me.close
     ElseIf e.Button = Windows.Forms.MouseButtons.Left then
         Me.Location.X = MousePosition.X
         Me.Location.Y = MousePosition.Y
     End If
End Sub

However the two lines after the "ElseIf" statement give me this error:

Expression is a value and t开发者_JAVA技巧herefore cannot be the target of an assignment.

How would I do this without it erroring?


You cannot set the X and Y of a co-ordinate individually. Try setting them together;

Private Sub SpaceInvadersControlButton_MouseDown (ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles SpaceInvadersControlButton.MouseDown
     If e.Button = Windows.Forms.MouseButtons.Right then
         Me.close
     ElseIf e.Button = Windows.Forms.MouseButtons.Left then
         Me.Location = MousePosition
     End If
End Sub
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜