|
Let¨s create a program that
enables the users to open and choose files from the folders
in their PC. This can be done easily using a picture box and
a common dialog box. In this program, you need to insert a
picture box, a common dialog box and an image. In the image
properties windows, click on the picture property and select
a picture that resembles an open file icon. The procedure
to open the common dialog box to browse the picture files as
well as to load the selected picture into the picture box is
CommonDialog1.Filter =
"Bitmaps(*.BMP)|*.BMP|Metafiles(*.WMF)|*.WMF|Jpeg
Files(*.jpg)|*.jpg|GIF Files(*.gif)|*.gif|Icon Files(*.ico)|*.ico|All
Files(*.*)|*.*"
CommonDialog1.ShowOpen
Picture1.Picture =
LoadPicture(CommonDialog1.FileName)
The filter property of the
common dialog box uses the format as shown below
Bitmaps(*.BMP)|*.BMP
to specify the file type, and
uses the pipe line | to separate different file types. |
Visual Basic supports most of
the picture formats namely bmp, wmf, jpg, gif, ico(icon) and
cur(cursor) files. The command
CommonDialog1.ShowOpen
is to open the common dialog box
and the command
Picture1.Picture = LoadPicture
(CommonDialog1.FileName)
is to load the selected picture
file into the picture box.
The whole program is shown below
and the output is shown in Figure 19.4
Private Sub Image1_Click()
CommonDialog1.Filter =
"Bitmaps(*.BMP)|*.BMP|Metafiles(*.WMF)|*.WMF|Jpeg
Files(*.jpg)|*.jpg|GIF Files(*.gif)|*.gif|Icon Files(*.ico)|*.ico|All
Files(*.*)|*.*"
CommonDialog1.ShowOpen
Picture1.Picture = LoadPicture
(CommonDialog1.FileName)
End Sub |