Private Sub UserForm_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer) If KeyCode = vbKeyZ Then For boucle = 0 To Controle.Controls.Count - 1 Controle.Controls(boucle).Top = Controle.Controls(boucle).Top + 10 Next Else If KeyCode = vbKeyS Then For boucle = 0 To Controle.Controls.Count - 1 Controle.Controls(boucle).Top = Controle.Controls(boucle).Top - 10 Next End If End If End Sub
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionPublic Class Controle Private Sub Controle_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown If e.KeyCode = ToucheAppuyée Then Exit Sub End If ToucheAppuyée = e.KeyCode If e.KeyCode = Keys.Z Then GoTo Haut Else If e.KeyCode = Keys.S Then GoTo Bas Else If e.KeyCode = Keys.Q Then GoTo Gauche Else If e.KeyCode = Keys.D Then GoTo Droite Else Exit Sub Haut: 'VERS LE HAUT Do While ToucheAppuyée = Keys.Z My.Application.DoEvents() For Each Control In Me.Controls If Control IsNot Boule Then Control.Location = New Point(Control.left, Control.top + 1) 'Control.Top += 1 End If Next Loop Bas: 'VERS LE BAS Do While ToucheAppuyée = Keys.S My.Application.DoEvents() For Each Control In Me.Controls If Control IsNot Boule Then Control.Location = New Point(Control.left, Control.top - 1) 'Control.Top -= 1 End If Next Loop Gauche: 'VERS LA GAUCHE Do While ToucheAppuyée = Keys.Q My.Application.DoEvents() For Each Control In Me.Controls If Control IsNot Boule Then Control.Location = New Point(Control.left + 1, Control.top) 'Control.left += 1 End If Next Loop Droite: 'VERS LA DROITE Do While ToucheAppuyée = Keys.D My.Application.DoEvents() For Each Control In Me.Controls If Control IsNot Boule Then Control.Location = New Point(Control.left - 1, Control.top) 'Control.left -= 1 End If Next Loop Suite: If AnciennePlateforme.Tag = "Gauche" And AnciennePlateforme.Left > -100 Then Plateformes() Else If AnciennePlateforme.Tag = "Droite" And AnciennePlateforme.Left < 100 Then Plateformes() Else If AnciennePlateforme.Tag = "Haut" And AnciennePlateforme.Top > -20 Then Plateformes() End If End If End If Me.Text = Me.Controls.Count End Sub Private Sub Controle_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyUp ToucheAppuyée = Keys.NumPad0 End Sub End Class
For Each Control In Me.Controls If Control IsNot Boule Then Control.Location = New Point(Control.left - 1, Control.top) 'Control.left -= 1 End If Next
If e.KeyCode = Keys.Z Then GoTo Haut Else If e.KeyCode = Keys.S Then GoTo Bas Else If e.KeyCode = Keys.Q Then GoTo Gauche Else If e.KeyCode = Keys.D Then GoTo Droite Else
Ce sont en fait les plateformes qui se déplacent et ma boule reste statique
Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown For Each Control In Me.Controls If e.KeyCode Keys.Q Then Control.Location New Point(Control.left - 2, Control.top) If e.KeyCode Keys.D Then Control.Location New Point(Control.left + 2, Control.top) If e.KeyCode Keys.Z Then Control.Location New Point(Control.left, Control.top - 2) If e.KeyCode Keys.S Then Control.Location New Point(Control.left, Control.top + 2) Next End Sub