2011-06-20 6 views
0

は、私は、コードを使用しようとしました:Visual Basicでは、クリックしたときにフォームの位置をポインタの位置に移動するにはどうすればよいですか?

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」ステートメントの後の2行は、私は、このエラーを与える:

Expression is a value and therefore cannot be the target of an assignment. 

私はそれがerroringせずにこれを行うだろうか?

答えて

1

座標の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 
+0

ありがとうございます。 – carstorm

関連する問題