Page 70 - Open Soource Technologies 304.indd
P. 70
Event Driven Programming
Figure 3.18: Background Changing.
Private Sub Form_Load()
BackColor = QBColor(Rnd * 15)
ForeColor = QBColor(Rnd * 10)
Picture1.BackColor = QBColor(Rnd * 15)
Picture1.ForeColor = QBColor(Rnd * 10)
End Sub
3.4.9.2 PictureBox Control
PictureBoxes are used to display images on them. The images displayed can be anything varying
from Bitmap, JPEG, GIF, PNG or any other image format files. The PictureBox control is based
on the Control class.
Notable property of the PictureBox Control in the Appearance section of the properties window
is the Image property which allows to add the image to be displayed on the PictureBox.
Adding Images to PictureBox
Images can be added to the PictureBox with the Image property from the Properties window or
by following lines of code.
Private Sub Button1_Click(ByVal sender As System.Object,_
ByVal e As System.EventArgs) Handles Button1.Click
PictureBox1.Image = Image.FromFile(“C:\sample.gif”)
’loading the image into the picturebox using the FromFile method of
the image class’
assuming a GIF image named sample in C: drive
End Sub
64 LOVELY PROFESSIONAL UNIVERSITY