Public Class Form1 ' Variables globales Dim LocationX As Integer Dim LocationY As Integer ' Utilise le Timer1 pour incrémenter les propriétés de pictureBox1 Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick LocationX += 1 LocationY += 1 PictureBox1.Top = LocationX PictureBox1.Left = LocationY If LocationX 100 Then Timer1.Enabled False End Sub ' Arrêter l'animation Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Timer1.Enabled = False End Sub ' Démarre l'animation Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Timer1.Enabled = True End Sub End Class
Public Class Form1 ' Variables globales Dim Objet As Control Dim X As Integer Dim Y As Integer Dim Xd As Integer Dim Yd As Integer Dim Xf As Integer Dim Yf As Integer ' Utilise le Timer1 pour incrémenter les propriétés de pictureBox1 Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick ' Paramètres Dim a As Double Dim b As Double ' Equation de droite a = (Yd - Yf) / (Xd - Xf) b = Yf - a * Xf ' Incrémentation X += 2 ' pas du décalage If X 1 Then X Xd Y = a * X + b ' Fin du déplacement au point d'arrivé If X > Xf Then Timer1.Enabled = False Exit Sub End If ' Déplacement Objet.Top = X Objet.Left = Y End Sub ' Arrêter/Reprend l'animation Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Timer1.Enabled (Timer1.Enabled False) End Sub ' Démarre l'animation Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click ' Défini objet et position Objet = PictureBox1 Xd = 12 Yd = 12 Xf = 100 Yf = 300 X = Xd Y = Yd ' lance l'animation Timer1.Interval = 10 Timer1.Enabled = True End Sub End Class
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click Timer2.Interval = 100 Timer2.Enabled = True End Sub Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick Angle += 1 X = Convert.ToInt32(100 * Math.Cos((Math.PI * Angle) / 180)) Y = Convert.ToInt32(100 * Math.Sin((Math.PI * Angle) / 180)) PictureBox1.Location = New Point(X + 100, Y + 100) End Sub
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre question