PictureBox Control in VB.net – Properties, Methods and Events

What is PictureBox Control in VB.net?

The PictureBox Control in VB.net is used for displaying images on the form.

The Image property of the control allows you to set an image both at design time or at run time.

Let’s create a picture box by dragging a PictureBox control from the Toolbox and dropping it on the form.

PictureBox Control in VB.net Tutorial
VB.net PictureBox Control Tutorial

Properties of PictureBox Control in VB.net

The following given below are some commonly used Properties of the PictureBox Control in VB.net.

#PictureBox Control in VB.net PropertiesDescription
1.BackColorIt is used to set the background color for the PictureBox in the window form.
2.BackgroundImageIt is used to set the background image of a window form by setting or getting value in the picture box.
3.ErrorImageThe ErrorImage property is used to display an image if an error occurs while loading an image on a window form.
4.InitialImageThe initial image is used to display an image on the PictureBox when the main image is loaded onto a window form by setting a value in the PictureBox control.
5.WaitOnLoadIt represents whether the particular image is synchronized or not in the PictureBox control.
6.TextIt is used to set text for the picture box controls in the window form.
7.ImageThe image property is used to display the image on the PictureBox of a Windows form.
8.BorderStyleIt is used to set the border style for the picture box in the windows form.
9.ImageLocationIt is used to set or get the path or URL of the image displayed on the picture box of the window form.
10.IsMirroredIt obtains a value that determines whether the picture box control is mirrored.
VB.net Properties and Description of PictureBox Control

Methods of PictureBox Control in VB.net

The following given below are some commonly used Methods of the PictureBox Control in VB.net.

#PictureBox Control in VB.net MethodsDescription
1.CancelAysnc()The CancelAsync method is used to cancel an asynchronous image load in a PictureBox control.
2.CreateHandle()It is used to create handles for the picture box controls in window form.
3.DestroyHandle()It is used to destroy all the handles that are associated with the picture box control.
4.GetStyle()The GetStyle() method is used to get values for the specified bit style in the PictureBox control.
5.Load()The Load() method is used to load the specified image from the control using the ImageLocation property.
6.LoadAsync(String)It is used to asynchronous load the image at the specified position of the picture box control.
VB.net Methods and Descriptions of PictureBox Control

Events of PictureBox Control in VB.net

The following given below are some commonly used Events of the PictureBox Control in VB.net.

#PictureBox Control in VB.net EventsDescription
1.CausesValidationChangedOverrides the Control.CausesValidationChanged property.
2.ClickOccurs when the control is clicked.
3.EnterOverrides the Control.Enter property.
4.FontChangedOccurs when the value of the Font property changes.
5.ForeColorChangedOccurs when the value of the ForeColor property changes.
6.KeyDownOccurs when a key is pressed when the control has focus.
7.KeyPressOccurs when a key is pressed when the control has focus.
8.KeyUpOccurs when a key is released when the control has focus.
9.LeaveOccurs when input focus leaves the PictureBox.
10.LoadCompletedOccurs when the asynchronous image-load operation is completed, been canceled, or raised an exception.
11.LoadProgressChangedOccurs when the progress of an asynchronous image-loading operation has changed.
12.ResizeOccurs when the control is resized.
13.RightToLeftChangedOccurs when the value of the RightToLeft property changes.
14.SizeChangedOccurs when the Size property value changes.
15.SizeModeChangedOccurs when SizeMode changes.
16.TabIndexChangedOccurs when the value of the TabIndex property changes.
17.TabStopChangedOccurs when the value of the TabStop property changes.
18.TextChangedOccurs when the value of the Text property changes.
Events and Descriptions of PictureBox Control

Let’s create a program to display an image in VB.net Windows form.

Public Class Form1
    Private Sub Button1_Click_1(sender As Object, e As EventArgs) Handles Button1.Click
        PictureBox1.Image = Image.FromFile("C:\Users\Lenovo\Desktop\pies.jpg")
        PictureBox1.SizeMode = PictureBoxSizeMode.StretchImage
        PictureBox1.Height = 500
        PictureBox1.Width = 800
    End Sub
End Class

Program Output:

PictureBox Control in VB.net Output
VB.net PictureBox Control Output

Now, click the view button to display the image in a Windows form.

PictureBox Control in VB.net Display Picture
VB.net PictureBox Control Display Picture

Summary

In this article we have discussed how to create a program for PictureBox in VB.net using Microsoft Visual Studio, we have learned how to use and manage the different Properties, Methods, and Events of the PictureBox in VB.net.


Leave a Comment