'樂透開獎機
Public Class Form1
Dim dx(10)
Dim dy(10)
Dim isStop(10) As Boolean
Dim stopLoc = 1
Dim pbox(10) As PictureBox
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Randomize()
Me.BackColor = Color.White
pbox(1) = PictureBox1
pbox(2) = PictureBox2
pbox(3) = PictureBox3
pbox(4) = PictureBox4
pbox(5) = PictureBox5
pbox(6) = PictureBox6
pbox(7) = PictureBox7
pbox(8) = PictureBox8
pbox(9) = PictureBox9
pbox(10) = PictureBox10
Timer1.Enabled = True
Timer1.Interval = 100
Dim i
For i = 1 To 10
isStop(i) = False
dx(i) = 1
dy(i) = 1
With pbox(i)
.Image = Image.FromFile("..\..\resources\b" & i & ".gif")
.Left = Int(Rnd() * 420 + 88)
.Width = 35
.Height = 35
.SizeMode = PictureBoxSizeMode.StretchImage
.BackColor = Color.White
End With
Next
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Dim i
For i = 1 To 10
If isStop(i) <> True Then
If pbox(i).Left > 275 And pbox(i).Left < 310 And pbox(i).Top > 366 And pbox(i).Top < 389 Then
pbox(i).Left = stopLoc
pbox(i).Top = 484
dx(i) = 0
dy(i) = 0
isStop(i) = True
stopLoc = stopLoc + pbox(1).Width
End If
pbox(i).Left = pbox(i).Left + 20 * dx(i)
If pbox(i).Left > 512 - 10 Then dx(i) = -1
If pbox(i).Left < 87 + 10 Then dx(i) = 1
pbox(i).Top = pbox(i).Top + 20 * dy(i)
If pbox(i).Top > 378 - 10 Then dy(i) = -1
If pbox(i).Top < 71 + 10 Then
dy(i) = 1
pbox(i).Top = pbox(i).Top + Int(Rnd() * 10) * dy(i)
End If
End If
Next
End Sub
End Class