Vb.net 在Visual Basic中,单击窗体时,如何将窗体的位置移动到指针的位置?
我尝试使用代码:Vb.net 在Visual Basic中,单击窗体时,如何将窗体的位置移动到指针的位置?,vb.net,Vb.net,我尝试使用代码: 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
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
但是,“ElseIf”语句后面的两行给了我这个错误:
Expression is a value and therefore cannot be the target of an assignment.
如何在不出错的情况下执行此操作?您不能单独设置坐标的X和Y。试着把它们放在一起
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