Page 232 - DCAP408_WEB_PROGRAMMING
P. 232
Windows Programming
Notes BorderColor, BorderWidth and BorderStyle properties. Similarly, to draw a shape, just click on
the shape control and draw the shape on the form.
Did u know? The default shape is a rectangle, with the shape property set at 0.
You can change the shape to square, oval, circle and rounded rectangle by changing the shape
property’s value to 1, 2, 3 4, and 5 respectively. In addition, you can change its background color
using the BackColor property, its border style using the BorderStyle property, its border color
using the BorderColor property as well its border width using the BorderWidth property.
14.7.2 The Image Box and the Picture Box
Using the line and shape controls to draw graphics will only enable you to create a simple
design. In order to improve the look of the interface, you need to put in images and pictures of
your own. Fortunately, there are two very powerful graphics tools you can use in Visual Basic
which are the image box and the picture box.
To load a picture or image into an image box or a picture box, you can click on the picture
property in the properties window and a dialog box will appear which will prompt the user to
select a certain picture file. You can also load a picture at runtime by using the LoadPicture ( )
method. The syntax is
Image1.Picture= LoadPicture(“C:\path name\picture file name”) or
picture1.Picture= LoadPicture(“C:\path name\picture name”)
Example: The following statement will load the grape.gif picture into the image box.
Image1.Picture= LoadPicture(“C:\My Folder\VB program\Images\grape.gif”)
Example: In this example, each time you click on the ‘change pictures’ button as shown
in Figure below, you will be able to see three images loaded into the image boxes. This program
uses the Rnd function to generate random integers and then uses the LoadPicture method to load
different pictures into the image boxes using the If…Then…Statements based on the random
numbers generated. The output is shown in Figure below
226 LOVELY PROFESSIONAL UNIVERSITY