Benutzer mit den meisten Antworten
Tastaturbefehle

Frage
Antworten
-
Ich habs rausgefunden:
Code SnippetPrivate Sub FormKeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyUp
If e.KeyCode = Keys.Up Then
PictureBox1.Location = New Point(PictureBox1.Location.X - 0, PictureBox1.Location.Y - 10)
ElseIf e.KeyCode = Keys.Down Then
PictureBox1.Location = New Point(PictureBox1.Location.X + 0, PictureBox1.Location.Y + 10)
ElseIf e.KeyCode = Keys.Right Then
PictureBox1.Location = New Point(PictureBox1.Location.X + 10, PictureBox1.Location.Y + 0)
ElseIf e.KeyCode = Keys.Left Then
PictureBox1.Location = New Point(PictureBox1.Location.X - 10, PictureBox1.Location.Y - 0)
End If
End Sub
Vorher aber bei der Form KeyPreview auf True setzen- Als Antwort markiert Kay GizaMicrosoft employee Montag, 20. Juli 2009 06:00
-
Es funktioniert auch folgender Code:
Dim y As Integer = pnlPacmanWASD.Location.Y
Dim x As Integer = pnlPacmanWASD.Location.X
If Asc(e.KeyChar) = 119 Then 'w
e.Handled = True
pnlPacmanWASD.Location = New Point(x, y - 10)
End If
If Asc(e.KeyChar) = 115 Then 's
e.Handled = True
pnlPacmanWASD.Location = New Point(x, y + 10)
End If
If Asc(e.KeyChar) = 97 Then 'a
e.Handled = True
pnlPacmanWASD.Location = New Point(x - 10, y)
End If
If Asc(e.KeyChar) = 100 Then 'd
e.Handled = True
pnlPacmanWASD.Location = New Point(x + 10, y)
End If- Als Antwort markiert Kay GizaMicrosoft employee Montag, 20. Juli 2009 06:00
Alle Antworten
-
Keyup ist ein Standardereignis von Formularen und Steuerelementen. Das tritt ein, wenn eine Taste gedrückt wurde und losgelassen wird.
QuellcodeabschnittPrivate Sub FormKeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyUp
If e.KeyCode.Up Then
Controlname.Location.Y -= 50
ElseIf e.KeyCode = Keys.Down ThenControlname.Location.Y += 50
End If End Sub -
Also ich habs so geschrieben
PictureBox1.Location.Y -= 50
ElseIf e.KeyCode = Keys.Down ThenPictureBox1.Location.Y(+50)
End If End SubDas was ich unterstrichen habe zeigt das Programm als Fehler an.
Bei dem erstem Fehler steht als Fehlerbeschreibung: Der Ausdruck ist ein Wert und kann nicht als Ziel einer Zuweisung verwendet werden.
Bei dem zweitem Fehler steht als Fehlerbeschreibung : Eigenschaftszugriff muss der Eigenschaft zugewiesen werden oder deren Wert verwenden.
-
Ich habs rausgefunden:
Code SnippetPrivate Sub FormKeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyUp
If e.KeyCode = Keys.Up Then
PictureBox1.Location = New Point(PictureBox1.Location.X - 0, PictureBox1.Location.Y - 10)
ElseIf e.KeyCode = Keys.Down Then
PictureBox1.Location = New Point(PictureBox1.Location.X + 0, PictureBox1.Location.Y + 10)
ElseIf e.KeyCode = Keys.Right Then
PictureBox1.Location = New Point(PictureBox1.Location.X + 10, PictureBox1.Location.Y + 0)
ElseIf e.KeyCode = Keys.Left Then
PictureBox1.Location = New Point(PictureBox1.Location.X - 10, PictureBox1.Location.Y - 0)
End If
End Sub
Vorher aber bei der Form KeyPreview auf True setzen- Als Antwort markiert Kay GizaMicrosoft employee Montag, 20. Juli 2009 06:00
-
Es funktioniert auch folgender Code:
Dim y As Integer = pnlPacmanWASD.Location.Y
Dim x As Integer = pnlPacmanWASD.Location.X
If Asc(e.KeyChar) = 119 Then 'w
e.Handled = True
pnlPacmanWASD.Location = New Point(x, y - 10)
End If
If Asc(e.KeyChar) = 115 Then 's
e.Handled = True
pnlPacmanWASD.Location = New Point(x, y + 10)
End If
If Asc(e.KeyChar) = 97 Then 'a
e.Handled = True
pnlPacmanWASD.Location = New Point(x - 10, y)
End If
If Asc(e.KeyChar) = 100 Then 'd
e.Handled = True
pnlPacmanWASD.Location = New Point(x + 10, y)
End If- Als Antwort markiert Kay GizaMicrosoft employee Montag, 20. Juli 2009 06:00