vbnet
  1. vbnet-picturebox-control

Working with Forms and Controls in VB.NET: PictureBox Control

The PictureBox control in VB.NET is used to display images in a form. It allows us to load and display images from files or resources, and to manipulate these images.

Syntax

PictureBox1.Image = Image.FromFile("image.jpg")

Here, PictureBox1 is the name of the PictureBox control, and Image.FromFile is a method used to load an image from a file.

Example

Public Class Form1
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        PictureBox1.Image = Image.FromFile("image.jpg")
    End Sub

    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        PictureBox1.Image.RotateFlip(RotateFlipType.Rotate90FlipNone)
        PictureBox1.Refresh()
    End Sub
End Class

Output

When the user clicks on Button1, an image file called "image.jpg" will be loaded and displayed in the PictureBox control. When the user clicks on Button2, the image will be rotated by 90 degrees clockwise and displayed again.

Explanation

In the above example, we have created a form with two buttons and a PictureBox control. When the user clicks on Button1, we use the method Image.FromFile to load an image from the file "image.jpg" and display it in the PictureBox control. When the user clicks on Button2, we use the RotateFlip method to rotate the image by 90 degrees clockwise, and then use the Refresh method to redraw the PictureBox control with the new image.

Use

The PictureBox control can be used to display images in a form, such as photographs, logos, or icons. It can also be used to create simple animation effects by changing the image displayed at regular intervals.

Important Points

  • The PictureBox control in VB.NET is used to display images in a form.
  • It allows us to load and display images from files or resources, and to manipulate these images.
  • The Image.FromFile method is used to load an image from a file.
  • The RotateFlip method can be used to rotate or flip an image, and the Refresh method can be used to redraw the PictureBox control with the new image.

Summary

In summary, the PictureBox control in VB.NET is a useful tool for displaying images in a form. It allows us to load and manipulate images easily, and can be used to create simple animation effects.

Published on: