Here is a simple program,
which shows random picture movement using timer control.
Program
Public Class Form1
Inherits System.Windows.Forms.Form
Dim i As Integer
Dim j As Integer
Dim k As Integer
Dim l As Integer
Dim m As Integer
Dim n As Integer
Dim spath As String
#Region " Windows Form Designer
generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows
Form Designer.
InitializeComponent()
'Add any initialization after the
InitializeComponent() call
End Sub
'Form overrides dispose to clean up the
component list.
Protected Overloads Overrides Sub
Dispose(ByVal disposing
As Boolean)
If disposing Then
If Not
(components Is Nothing)
Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As
System.ComponentModel.IContainer
'NOTE: The following procedure is
required by the Windows Form Designer
'It can be modified using the Windows
Form Designer.
'Do not modify it using the code
editor.
Friend WithEvents Timer2
As System.Windows.Forms.Timer
Friend WithEvents PictureBox2
As System.Windows.Forms.PictureBox
Friend WithEvents Timer1
As System.Windows.Forms.Timer
Friend WithEvents PictureBox1
As System.Windows.Forms.PictureBox
Friend WithEvents PictureBox3
As System.Windows.Forms.PictureBox
Friend WithEvents PictureBox4
As System.Windows.Forms.PictureBox
Friend WithEvents PictureBox5
As System.Windows.Forms.PictureBox
Friend WithEvents PictureBox6
As System.Windows.Forms.PictureBox
Friend WithEvents Timer3
As System.Windows.Forms.Timer
Friend WithEvents Timer4
As System.Windows.Forms.Timer
Friend WithEvents Timer5
As System.Windows.Forms.Timer
Friend WithEvents Timer6
As System.Windows.Forms.Timer
<System.Diagnostics.DebuggerStepThrough()>
Private Sub InitializeComponent()
Me.components = New
System.ComponentModel.Container
Me.Timer2 = New
System.Windows.Forms.Timer(Me.components)
Me.PictureBox2 = New
System.Windows.Forms.PictureBox
Me.Timer1 = New
System.Windows.Forms.Timer(Me.components)
Me.PictureBox1
= New System.Windows.Forms.PictureBox
Me.PictureBox3 = New
System.Windows.Forms.PictureBox
Me.PictureBox4 = New
System.Windows.Forms.PictureBox
Me.PictureBox5 = New
System.Windows.Forms.PictureBox
Me.PictureBox6 = New
System.Windows.Forms.PictureBox
Me.Timer3 = New
System.Windows.Forms.Timer(Me.components)
Me.Timer4 = New
System.Windows.Forms.Timer(Me.components)
Me.Timer5 = New
System.Windows.Forms.Timer(Me.components)
Me.Timer6
= New System.Windows.Forms.Timer(Me.components)
Me.SuspendLayout()
'
'Timer2
'
Me.Timer2.Interval = 1250
'
'PictureBox2
'
Me.PictureBox2.Location =
New System.Drawing.Point(176, 16)
Me.PictureBox2.Name = "PictureBox2"
Me.PictureBox2.Size =
New System.Drawing.Size(144, 112)
Me.PictureBox2.TabIndex = 3
Me.PictureBox2.TabStop = False
'
'Timer1
'
Me.Timer1.Interval = 1200
'
'PictureBox1
'
Me.PictureBox1.Location =
New System.Drawing.Point(16, 16)
Me.PictureBox1.Name = "PictureBox1"
Me.PictureBox1.Size =
New System.Drawing.Size(144, 112)
Me.PictureBox1.TabIndex = 2
Me.PictureBox1.TabStop = False
'
'PictureBox3
'
Me.PictureBox3.Location =
New System.Drawing.Point(336, 16)
Me.PictureBox3.Name = "PictureBox3"
Me.PictureBox3.Size =
New System.Drawing.Size(144, 112)
Me.PictureBox3.TabIndex = 4
Me.PictureBox3.TabStop = False
'
'PictureBox4
'
Me.PictureBox4.Location =
New System.Drawing.Point(16, 144)
Me.PictureBox4.Name = "PictureBox4"
Me.PictureBox4.Size
= New System.Drawing.Size(144, 112)
Me.PictureBox4.TabIndex = 5
Me.PictureBox4.TabStop = False
'
'PictureBox5
'
Me.PictureBox5.Location =
New System.Drawing.Point(176, 144)
Me.PictureBox5.Name = "PictureBox5"
Me.PictureBox5.Size =
New System.Drawing.Size(144, 112)
Me.PictureBox5.TabIndex = 6
Me.PictureBox5.TabStop = False
'
'PictureBox6
'
Me.PictureBox6.Location =
New System.Drawing.Point(336, 144)
Me.PictureBox6.Name = "PictureBox6"
Me.PictureBox6.Size =
New System.Drawing.Size(144, 112)
Me.PictureBox6.TabIndex = 7
Me.PictureBox6.TabStop = False
'
'Timer3
'
Me.Timer3.Interval
= 1300
'
'Timer4
'
Me.Timer4.Interval = 1350
'
'Timer5
'
Me.Timer5.Interval = 1400
'
'Timer6
'
Me.Timer6.Interval = 1450
'
'Form1
'
Me.AutoScaleBaseSize =
New System.Drawing.Size(5, 13)
Me.ClientSize = New
System.Drawing.Size(568, 326)
Me.Controls.Add(Me.PictureBox6)
Me.Controls.Add(Me.PictureBox5)
Me.Controls.Add(Me.PictureBox4)
Me.Controls.Add(Me.PictureBox3)
Me.Controls.Add(Me.PictureBox2)
Me.Controls.Add(Me.PictureBox1)
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub Form1_Load(ByVal
sender As System.Object,
ByVal e As
System.EventArgs) Handles MyBase.Load
spath =
Mid(Application.StartupPath, 1, Len(Application.StartupPath) - 3)
Timer1.Enabled =
True
Timer2.Enabled =
True
Timer3.Enabled =
True
Timer4.Enabled =
True
Timer5.Enabled =
True
Timer6.Enabled =
True
End Sub
Private Sub Timer1_Tick(ByVal
sender As System.Object,
ByVal e As
System.EventArgs) Handles Timer1.Tick
Dim a1 As New Random
Try
i = a1.Next(1, 26)
PictureBox1.Image
= Image.FromFile(spath & "mindgame/image1/p"
& i & ".jpg")
Catch ex As
Exception
MsgBox(ex.Message)
End Try
End Sub
Private Sub Timer2_Tick(ByVal
sender As System.Object,
ByVal e As
System.EventArgs) Handles Timer2.Tick
Dim a2 As New Random
Try
j = a2.Next(1, 26)
PictureBox2.Image
= Image.FromFile(spath & "mindgame/image1/p"
& j & ".jpg")
Catch ex As
Exception
MsgBox(ex.Message)
End Try
End Sub
Private Sub Timer3_Tick(ByVal
sender As System.Object,
ByVal e As
System.EventArgs) Handles Timer3.Tick
Dim a3 As New Random
Try
k = a3.Next(1, 26)
PictureBox3.Image
= Image.FromFile(spath & "mindgame/image1/p"
& k & ".jpg")
Catch ex As
Exception
MsgBox(ex.Message)
End Try
End Sub
Private Sub Timer4_Tick(ByVal
sender As System.Object,
ByVal e As
System.EventArgs) Handles Timer4.Tick
Dim a4 As New Random
Try
l = a4.Next(1, 26)
PictureBox4.Image
= Image.FromFile(spath & "mindgame/image1/p"
& l & ".jpg")
Catch ex As
Exception
MsgBox(ex.Message)
End Try
End Sub
Private Sub Timer5_Tick(ByVal
sender As System.Object,
ByVal e As
System.EventArgs) Handles Timer5.Tick
Dim a5 As New Random
Try
m = a5.Next(1, 26)
PictureBox5.Image
= Image.FromFile(spath & "mindgame/image1/p"
& m & ".jpg")
Catch ex As
Exception
MsgBox(ex.Message)
End Try
End Sub
Private Sub Timer6_Tick(ByVal
sender As System.Object,
ByVal e As
System.EventArgs) Handles Timer6.Tick
Dim a6 As New Random
Try
n = a6.Next(1, 26)
PictureBox6.Image
= Image.FromFile(spath & "mindgame/image1/p"
& n & ".jpg")
Catch ex As
Exception
MsgBox(ex.Message)
End Try
End Sub
End Class