GroupBox and PictureBox control in ASP.NET Using VB.NET

In this article you will learn about GroupBox and PictureBox,their properties and how can you use GroupBox at runtime and PictureBox by a small code.
  • 5870
Download Files:
 

GroupBox

A visual basic GroupBox control is used to group controls. GroupBox display a frame around them and also allow to display caption to them. GroupBoxes are similar to Panels but the difference, Panels can not display caption where as GroupBoxes can. GroupBox is a container of other control, when you move the GroupBox control all of it's contained also move. This control contain a border by default. The GroupBox class is based on the Control class.

Properties of GroupBox control

  • Text:- Text property of a GroupBox control represents the header Text of a control.
  • BackColor:- This property is used to set the Background color of the GroupBox. 
  • Name:- Name property is used to represent a unique name of a GroupBox control. 
  • Font:- Font property represents the Font of Header Text of a GroupBox control.

PictureBox

PictureBoxes are used to Display images on them. The images displayed can be anything varying from Bitmap, JPEG, GIF, PNG or any other image format file. The PictureBox control is also based on the Control class. We can display an image by adding it in the Image property of the PictureBox control or you can also display an Image by some lines of code as we did in this article.

Properties of PictureBox control

  • Image:- This property allow to add Image to be displayed on the PictureBox. 
  • SizeMode:- This property sets the Image SizeMode.by default it set to normal.
  • BorderStyle:- This property set the BorderStyle of the control.
  • Stretch:- This property determines whether the Image is resized or not.

Mostly you use GroupBox control on Design Time and image appears using Image property of the PictureBox. But here we are taking an example by which GroupBox control will appear on Runtime and image in the PictureBox will display by some lines of code not by setting Image property.

How to use GroupBox control at Runtime and display image in PictureBox by coding

  • Simply open a new Project.
  • Drag a PictureBox, Button control on form. The form will display like below.

    GroupBox-PictureBox1.gif
     
  • Write the Below code

       Private Sub Form1_Load(ByVal sender As System.Object, ByVal e_ As System.EventArgs) Handles MyBase.Load
        Dim GroupBox1 As New GroupBox()
        Dim CheckBox1 As New CheckBox()
        Dim Label1 As New Label()
        GroupBox1.Location = New Point(20, 50)
        GroupBox1.Size = New Size(150, 164)
        GroupBox1.Text = "InGroupBox"
        'setting the caption to the groupbox
        Me.Controls.Add(GroupBox1)
        CheckBox1.Size = New Size(95, 45)
        CheckBox1.Location = New Point(20, 30)
        CheckBox1.Text = "Checkbox1"
        Label1.Size = New Size(100, 50)
        Label1.Location = New Point(20, 40)
        Label1.Text = "CheckMe"
        GroupBox1.Controls.Add(CheckBox1)
        GroupBox1.Controls.Add(Label1)
        'adding the label and checkbox to the groupbox
    End Sub
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        PictureBox1.Image = Image.FromFile("c:\Comp.gif")
        'loading the image into the picturebox using the FromFile method of the image class
        'assuming a GIF image named Comp in C: drive
    End Sub

Output

GroupBox-PictureBox2.gif

GroupBox-PictureBox4.gif

GroupBox-PictureBox3.gif

Categories

More Articles

© 2019 DotNetHeaven. All rights reserved.