Utiliser les touches directionnelles en .net

Résolu/Fermé
Alvin1614 Messages postés 107 Date d'inscription lundi 24 avril 2017 Statut Membre Dernière intervention 22 décembre 2021 - 14 avril 2018 à 18:25
cs_Le Pivert Messages postés 7903 Date d'inscription jeudi 13 septembre 2007 Statut Contributeur Dernière intervention 11 mars 2024 - 28 avril 2018 à 16:10
Bonjour,

Je suis sur une réalisation en vb.

C'est un bonhomme que l'on peut faire bouger avec les touches directionnelles.
Il y a des monstres invisibles qui au fur et à mesure apparaissent et attaquent le bonhomme en lui tirant dessus. Le problème, c'est que je n'arrive pas à le faire bouger :
Select Case e.KeyCode
            Case Keys.Down
                Me.PictureBox1.Location = Location.Y -1
            Case Keys.Up

            Case Keys.Left

            Case Keys.Right


Je sais que le
Location.Y -1
ça n'existe pas, mais je ne sais pas comment faire...

Merci d'avance,

Alvin1614
A voir également:

2 réponses

yg_be Messages postés 22711 Date d'inscription lundi 9 juin 2008 Statut Contributeur Dernière intervention 21 avril 2024 1 474
14 avril 2018 à 21:49
bonsoir, peut-être:
Me.PictureBox1.Location = New Point(Me.PictureBox1.Location.X , Me.PictureBox1.Location.Y -1)
0
Whismeril Messages postés 19026 Date d'inscription mardi 11 mars 2003 Statut Contributeur Dernière intervention 20 avril 2024 931
14 avril 2018 à 22:04
Bonsoir
ou
Me.PictureBox1.Location.Y = Me.PictureBox1.Location.Y -1 

J'ai pas testé
0
Merci pour votre aide mais ça ne marche toujours pas à cause de ceci :
Select Case e.KeyCode

Je ne peut donc tester vos solutions étant donné qu'il m'affiche : 'KeyCode' n'est pas un membre de 'System.EventArgs'.
0
yg_be Messages postés 22711 Date d'inscription lundi 9 juin 2008 Statut Contributeur Dernière intervention 21 avril 2024 1 474 > Alvin1614
28 avril 2018 à 11:14
Merci pour ta question, mais nous ne pouvons pas t'aider étant donné que tu ne nous montres pas comment tu as déclaré et obtenu e.
0
cs_Le Pivert Messages postés 7903 Date d'inscription jeudi 13 septembre 2007 Statut Contributeur Dernière intervention 11 mars 2024 728
28 avril 2018 à 16:10
Bonjour,

Comme ceci:

Option Strict On
Public Class Form1
    Private Sub Form1_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
        Select Case e.KeyCode
            Case Keys.Down
                If Me.PictureBox1.Location.Y = Me.Height - PictureBox1.Height Then Exit Sub
                Me.PictureBox1.Location = New System.Drawing.Point(Me.PictureBox1.Location.X, Me.PictureBox1.Location.Y + 1)
            Case Keys.Up
                If Me.PictureBox1.Location.Y = 0 Then Exit Sub
                Me.PictureBox1.Location = New System.Drawing.Point(Me.PictureBox1.Location.X, Me.PictureBox1.Location.Y - 1)
            Case Keys.Left
                If Me.PictureBox1.Location.X = 0 Then Exit Sub
                Me.PictureBox1.Location = New System.Drawing.Point(Me.PictureBox1.Location.X - 1, Me.PictureBox1.Location.Y)
            Case Keys.Right
                If Me.PictureBox1.Location.X = Me.Width - PictureBox1.Width Then Exit Sub
                Me.PictureBox1.Location = New System.Drawing.Point(Me.PictureBox1.Location.X + 1, Me.PictureBox1.Location.Y)
        End Select
    End Sub
End Class


Voilà
0