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.
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 Properties||Description|
|1.||BackColor||It is used to set the background color for the PictureBox in the window form.|
|2.||BackgroundImage||It is used to set the background image of a window form by setting or getting value in the picture box.|
|3.||ErrorImage||The ErrorImage property is used to display an image if an error occurs while loading an image on a window form.|
|4.||InitialImage||The 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.||WaitOnLoad||It represents whether the particular image is synchronized or not in the PictureBox control.|
|6.||Text||It is used to set text for the picture box controls in the window form.|
|7.||Image||The image property is used to display the image on the PictureBox of a Windows form.|
|8.||BorderStyle||It is used to set the border style for the picture box in the windows form.|
|9.||ImageLocation||It is used to set or get the path or URL of the image displayed on the picture box of the window form.|
|10.||IsMirrored||It obtains a value that determines whether the picture box control is mirrored.|
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 Methods||Description|
|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.|
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 Events||Description|
|1.||CausesValidationChanged||Overrides the Control.CausesValidationChanged property.|
|2.||Click||Occurs when the control is clicked.|
|3.||Enter||Overrides the Control.Enter property.|
|4.||FontChanged||Occurs when the value of the Font property changes.|
|5.||ForeColorChanged||Occurs when the value of the ForeColor property changes.|
|6.||KeyDown||Occurs when a key is pressed when the control has focus.|
|7.||KeyPress||Occurs when a key is pressed when the control has focus.|
|8.||KeyUp||Occurs when a key is released when the control has focus.|
|9.||Leave||Occurs when input focus leaves the PictureBox.|
|10.||LoadCompleted||Occurs when the asynchronous image-load operation is completed, been canceled, or raised an exception.|
|11.||LoadProgressChanged||Occurs when the progress of an asynchronous image-loading operation has changed.|
|12.||Resize||Occurs when the control is resized.|
|13.||RightToLeftChanged||Occurs when the value of the RightToLeft property changes.|
|14.||SizeChanged||Occurs when the Size property value changes.|
|15.||SizeModeChanged||Occurs when SizeMode changes.|
|16.||TabIndexChanged||Occurs when the value of the TabIndex property changes.|
|17.||TabStopChanged||Occurs when the value of the TabStop property changes.|
|18.||TextChanged||Occurs when the value of the Text property changes.|
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
Now, click the view button to display the image in a Windows form.
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.