[go: up one dir, main page]

0% found this document useful (0 votes)
8 views13 pages

Visual Basic 4 - 1

This document provides a tutorial on handling images in VB.NET, covering how to load images into a picture box at design time and runtime. It also explains the use of the OpenFileDialog control to allow users to browse and select images from their local drives. The tutorial includes code examples and instructions for setting up the image viewer application.

Uploaded by

q25642754
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views13 pages

Visual Basic 4 - 1

This document provides a tutorial on handling images in VB.NET, covering how to load images into a picture box at design time and runtime. It also explains the use of the OpenFileDialog control to allow users to browse and select images from their local drives. The tutorial includes code examples and instructions for setting up the image viewer application.

Uploaded by

q25642754
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

Ministry of Higher Education

Ghor Institute of Higher Education


Computer Science Department

VB.NET
Handling Images

Presented by :hamidullah ahmadi


Email : hamidullahdadras@gmail.com
Contents
❖ Learn to load image in a picture box
❖ Learn to browse and load images using the common dialog
Loading an Image at Design Time
In this section, let us develop an image viewer . To create an image viewer,
we insert a picture box in the form. Next, change its border property to
FixedSingle and its background color to white. You might also want to
change the SizeMode property of the image to StretchImage so that the image
can fit in the picture box. In the properties window, scroll to the Image
property.
Con…
The next step is to select local resource and click on the Import button to
view the available image files in your local drives, as shown in Figure 5.3.
Finally, select the image you like and then click the open button, the image
will be displayed in the picture box, as shown in Figure 5.4
Loading an Image at Runtime
We can also load an image at runtime, using the code as follows:

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles

MyBase.Load

PictureBox1.Image = Image.FromFile("C:\Users\Toshiba\Pictures\My

Pictures\USA\Chicago 2012.jpg")

End Sub

* You need to search for an image in your local drive and determine its path.

Running the program will display the same image in the picture box as in Figure 5.4
Loading an Image using Open File Dialog Control
To load an image in a picture box using the OpenFileDialog control, we must add the
OpenFileDialog control on the form. This control will be invisible during runtime, but it
facilitates the process of launching a dialog box and let the user browse his or her local drives and
then select and open a file. For the OpenFileDialogto display all types of image files, we must
specify the types of image files under the Filter property. Before that, rename OpenFileDialogas
OFGSelectImage. Next, right click on the OpenFileDialog control to access its properties
window. Beside the Filter property, specify the image files using the format:

JPEG Files| *.JPG|GIF Files|*.GIF|WIndows Bitmaps|*.BMP

as shown in Figure 5.5. These are the common image file formats. Besides that, you need

to delete the default Filename.


Con…
Con…
Next, double-click on the View button and enter the following code:

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles

Button1.Click

If OFGSelectImage.ShowDialog = Windows.Forms.DialogResult.OK
Then

PictureBox1.Image = Image.FromFile(OFGSelectImage.FileName)

End If

End Sub
Summary

● In section 5.11, you have learned how to load an image at design


time using the properties window

● In section 5.1.2, you have learned how to load an image at runtime

● In section 5.2, you have learned how to load an image using the
OpenFileDialog control
Be Success!
Any Question?

You might also like