0% found this document useful (0 votes)
29 views2 pages

Form1 Eventargs Random: ' Lets Go With A Low Number For Smoother Animation

Program 2 simulates rolling a dice by generating a random number between 1 and 25 and displaying it. Program 3 moves a label downward each time a timer ticks. It stops the timer when the label reaches the bottom of the form. A button click starts and stops the timer. The third program uses a timer and image list to animate a slideshow. It increments a counter each tick to change the image, and resets the counter when it reaches the end of the image list. A button click starts and stops the timer to play and pause the slideshow.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views2 pages

Form1 Eventargs Random: ' Lets Go With A Low Number For Smoother Animation

Program 2 simulates rolling a dice by generating a random number between 1 and 25 and displaying it. Program 3 moves a label downward each time a timer ticks. It stops the timer when the label reaches the bottom of the form. A button click starts and stops the timer. The third program uses a timer and image list to animate a slideshow. It increments a counter each tick to change the image, and resets the counter when it reaches the end of the image list. A button click starts and stops the timer to play and pause the slideshow.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Program 2

Public Class Form1


Private Sub btnroll_Click(sender As Object, e As EventArgs) Handles btnroll.Click
Dim oDice As New Random
Dim iDiceResult As Integer = oDice.Next(1, 25)
lbldiceoutput.Text = iDiceResult.ToString
End Sub
End Class

Program 3
Public Class Form1
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
' Lets go with a low number for smoother animation
Label1.Top = Label1.Top + 3
Dim bottomValue As Integer = Label1.Top + Label1.Height
' Check if the bottom of the label has hit the bottom of our form
' If so, stop the timer.
If bottomValue >= Me.ClientRectangle.Height Then
Timer1.Stop()
End If
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Timer1.Start()
End Sub
End Class

Public Class Form1


2
' A form level variable to hold which frame is to show
' It has to be form level so that our timer1_tick event knows about it from
3
call to call
4
Dim imageNumber As Integer = 0
5
' Our form load even just sets the picturebox's image to the first one in the
6
list
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
7
System.EventArgs) Handles MyBase.Load
8
PictureBox1.Image = ImageList1.Images(0)
9
End Sub
10
' The timer event here picks up the frame from the imagelist control and
11
sets the picturebox
12
' It then increments to the next frame in the list.
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As
13
System.EventArgs) Handles Timer1.Tick
14
PictureBox1.Image = ImageList1.Images(imageNumber)
15
imageNumber = imageNumber + 1
16
' If the frame variable is greater than the total images we have in the
17
list
' (minus 1 because they are arranged on a zero index system) then we
18
reset the frame count
19
If imageNumber > ImageList1.Images.Count - 1 Then
20
imageNumber = 0
21
End If
22
End Sub
23
' This simply starts and stops the timer. If the timer is running, stop it,
24
otherwise it is
25
' stopped so start it.
26
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
27
System.EventArgs) Handles Button1.Click
28
If Timer1.Enabled Then
29
Timer1.Stop()
30
Else
31
Timer1.Start()
32
End If
33
End Sub
34
End Class

You might also like