0
如何在兩個方向鍵被按下時以對角線方式移動物體?怎麼做? 我嘗試添加ELSEIF語句處理向上和向右在一起,但它仍然向上或權當我一起按他們VB.NET使用鍵對角移動物體
Private Sub Form1_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
If e.KeyCode = Keys.Right Then
Label1.Location = New Point(Label1.Location.X + 5, Label1.Location.Y)
ElseIf e.KeyCode = Keys.Left Then
Label1.Location = New Point(Label1.Location.X - 5, Label1.Location.Y)
ElseIf e.KeyCode = Keys.Down Then
Label1.Location = New Point(Label1.Location.X, Label1.Location.Y + 5)
ElseIf e.KeyCode = Keys.Up Then
Label1.Location = New Point(Label1.Location.X, Label1.Location.Y - 5)
ElseIf e.KeyCode = Keys.Up And e.KeyCode = Keys.Right Then
Label1.Location = New Point(Label1.Location.X + 5, Label1.Location.Y + 5)
End If
CheckIntersections()
If Label1.Location.Y < 0 Then
Label1.Location = New Point(Label1.Location.X, Me.Height)
ElseIf Label1.Location.Y > Me.Height Then
Label1.Location = New Point(Label1.Location.X, Me.Bottom = 0)
ElseIf Label1.Location.X < 0 Then
Label1.Location = New Point(Me.Width, Label1.Location.Y)
ElseIf Label1.Location.X > Me.Width Then
Label1.Location = New Point(0, Label1.Location.Y)
End If
End Sub
當兩個光標鍵被按下時,你能編碼對象的對角線移動嗎? – conquistador 2013-03-09 09:21:07
@XtraCode沒有任何時間(我遠離我的開發系統)。 – Richard 2013-03-09 09:22:02