1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
| Public Class Form1
Dim value As Integer
Dim Key As Boolean = False
Private counter As Integer
Private lb As New Label
Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
lb.Text = "Mais non pour arrêter il faut trouver la bonne touche"
Threading.Thread.Sleep(600)
If e.KeyValue = value Then
Key = True
End If
counter -= 1
If counter = 1 Then
lb.Text = "encore un essais"
End If
If counter = 0 Then
Key = True
End If
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Me.Load
Me.KeyPreview = True
lb.Font = New Font("arial", 12, FontStyle.Bold)
lb.AutoSize = True
lb.Text = "Appuyez sur une touche pour sortir de cette galère..."
lb.Location = New Point(10, 10)
Me.Controls.Add(lb)
counter = 4
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim Vitesse As Integer = 10
Dim Pos_1 As Integer = Me.Location.X
Dim Pos_2 As Integer = Me.Location.Y
Dim Random As New Random(), Rnd As Integer
Dim Emplac As Point
Dim SensX As Boolean
Dim SensY As Boolean
value = Random.Next(Convert.ToInt32("a"c), Convert.ToInt32("z"c))
Do
Rnd = Random.Next(1, 9)
If SensX = True Then
Emplac = New Point(Me.Location.X + Rnd, Me.Location.Y)
If Me.Location.X + Rnd >= (Screen.PrimaryScreen.Bounds.Width - Me.Width) Then SensX = False
Else
Emplac = New Point(Me.Location.X - Rnd, Me.Location.Y)
If Me.Location.X - Rnd <= 0 Then SensX = True
End If
Me.Location = Emplac
Application.DoEvents()
Threading.Thread.Sleep(Vitesse)
Rnd = Random.Next(1, 9)
If SensY = True Then
Emplac = New Point(Me.Location.X, Me.Location.Y + Rnd)
If Me.Location.Y + Rnd >= (Screen.PrimaryScreen.Bounds.Height - Me.Height) Then SensY = False
Else
Emplac = New Point(Me.Location.X, Me.Location.Y - Rnd)
If Me.Location.Y - Rnd <= 0 Then SensY = True
End If
Me.Location = Emplac
Application.DoEvents()
If Key = True Then Exit Do
Loop
Key = False
counter = 4
lb.Text = "Appuyez sur une touche pour sortir de cette galère..."
End Sub
End Class |
Partager