Microsoft visual basic 2005 Express.
how to make random pictures appear in the picture box?
What is the code??
It's for the design in my project. ^_^
Is it possible? I want random pictures appear on it.
Example, there are five pictures i want to be displayed in the picturebox in random. how??How to make random pictures appear on the picturebox in VB 2005 Express?
One way of doing it is:
First you need to generate random numbers from 1 to 5 and store the value in an integer variable. Then all you have to do is use a swicth case in a timer object. Set the timer object to execute as often as you want the pictures to change,
i.e.
switch (randomNum)
{
case 1:
picBox.picture(';Picture1';)
break
case 2:
picBox.picture(';Picture2';)
break
etc...
}
This is pseudocode but you get the point!How to make random pictures appear on the picturebox in VB 2005 Express?
You would need an array with the path to all your pics. EG:
Public picArr (1 to 4) as string
Public PicCount as integer
Private Sub Form_Load()
picArr(1)=';c:/me.jpg';
picArr(2)=';c:/myDog.jpg';
picArr(3)=';c:/Airport.jpg';
picArr(4)=';c:/pics/Madagascar.jpg';
PicCount=4
End Sub
Public Sub ChangePicture ()
dim x as decimal
x=rand(Now())
x=x*(picCount-1)
x=x+1
picBox1.picture=openpicture (picArr(cint(x)))
end sub
I think that's right... I stand to be corrected.
Hope you get it right,
Matt :)
No comments:
Post a Comment