Picturebox mit den Pfeiltasten bewegen

  • VB.NET

Es gibt 2 Antworten in diesem Thema. Der letzte Beitrag () ist von tomboy97.

    Picturebox mit den Pfeiltasten bewegen

    Hey Leute ich würde gerne eine Picturebox mit den Pfeiltasten bewegen. Doch wei bekomme ich das hin. Den code für das bewegen mit buttons weis ich aber wie mit Pfeiltasten????

    Danke im voraus!!! 8-) 8-) 8-) :D :D :D :rolleyes: :rolleyes: :rolleyes:

    Edit by Agent: Bitte nur aussagekräftige Titel benutzen!!! > geändert

    Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von „Agent“ ()

    Beispielcode:
    Du brauchst...
    -einen Timer (tmr_main) (.Interval = 10; .Enabled = True)
    -ein Form (frm_main)
    -und eine PictureBox (PicBox)

    VB.NET-Quellcode

    1. Public Class frm_main
    2. Dim key As Keys = Nothing
    3. Private Sub frm_main_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
    4. key = e.KeyCode()
    5. End Sub
    6. Private Sub tmr_main_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmr_main.Tick
    7. If (key = Keys.Left) Then
    8. PicBox.Location = New Point(PicBox.Location.X - 4, PicBox.Location.Y)
    9. ElseIf (key = Keys.Right) Then
    10. PicBox.Location = New Point(PicBox.Location.X + 4, PicBox.Location.Y)
    11. ElseIf (key = Keys.Up) Then
    12. PicBox.Location = New Point(PicBox.Location.X, PicBox.Location.Y - 4)
    13. ElseIf (key = Keys.Down) Then
    14. PicBox.Location = New Point(PicBox.Location.X, PicBox.Location.Y + 4)
    15. End If
    16. End Sub
    17. End Class