ARTICLE

Working of GroupBox and PictureBox control in VB.NET

Posted by Shalini Juneja Articles | ASP.NET using VB.NET April 06, 2011
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.
Download Files:
 
Reader Level:

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 BakGround 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 DesignTime 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

Login to add your contents and source code to this article
share this article :
post comment
 
Nevron Diagram
Become a Sponsor
PREMIUM SPONSORS
  • ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications.
    Get 2 Months Free of ASP.NET Hosting for Only $4.95/month! Receive FREE MS SQL and MySQL Databases Including ASP.NET 4/3.5, MVC 3.0, Silverlight 4, Windows 2008/IIS 7.0 Plus FREE IIS 7 Modules. Host UNLIMITED ASP.NET Web Sites - Click Here!
6 Months Free & No Setup Fees ASP.NET Hosting!
Become a Sponsor