Search | Contact | Link To Us  

      VB .NET       

.NET Defined
OOP with VB
VB Language
Win Forms
Windows Controls
ADO .NET
User Controls
File Handling
Multithreading
Deployment
XML Web Services Essential XML
Resources
Discussions
ASP.NET
About



Advertisement


     Home> Windows Controls> Panel, GroupBox, PictureBox


Panel, GroupBox, PictureBox

Panel

Panels are those controls which contain other controls, for example, a set of radio buttons, checkboxes, etc. Panels are similar to Groupboxes but the difference, Panels cannot display captions where as GroupBoxes can and Panels can have scrollbars where as GroupBoxes can't. If the Panel's Enabled property is set to False then the controls which the Panel contains are also disabled. Panels are based on the ScrollableControl class.

Notable property of the Panel control in the appearance section is the BorderStyle property. The default value of the BorderStyle property is set to None. You can select from the predefined list to change a Panels BorderStyle.
Notable property in the layout section is the  AutoScroll property. Default value is set to False. Set it to True if you want a scrollbar with the Panel.

Adding Controls to a Panel

On a from drag a Panel (Panel1) from the toolbox. We want to place some controls, say, checkboxes on this Panel. Drag three checkboxes from the toolbox and place them on the Panel. When that is done all the checkboxes in the Panel are together as in a group but they can function independently.

Creating a Panel and adding a Label and a CheckBox to it in Code

Private Sub Form3_Load(ByVal sender As System.Object, ByVal e_
As System.EventArgs) Handles MyBase.Load
Dim Panel1 As New Panel()
Dim CheckBox1 As New CheckBox()
Dim Label1 As New Label()
Panel1.Location = New Point(30, 60)
Panel1.Size = New Size(200, 264)
Panel1.BorderStyle = BorderStyle.Fixed3D
'setting the borderstyle of the panel
Me.Controls.Add(Panel1)
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"
Panel1.Controls.Add(CheckBox1)
Panel1.Controls.Add(Label1)
'adding the label and checkbox to the panel
End Sub

The image below displays a panel.

Panel, GroupBox, PictureBox

GroupBox Control

As said above, Groupboxes are used to Group controls. GroupBoxes display a frame around them and also allows to display captions to them which is not possible with the Panel control. The GroupBox class is based on the Control class.

Creating a GroupBox and adding a Label and a CheckBox to it in 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(30, 60)
GroupBox1.Size = New Size(200, 264)
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

PictureBox Control

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 files. The PictureBox control is based on the Control class.

Notable property of the PictureBox Control in the Appearance section of the properties window is the Image property which allows to add the image to be displayed on the PictureBox.

Adding Images to PictureBox

Images can be added to the PictureBox with the Image property from the Properties window or by following lines of code.

Private Sub Button1_Click(ByVal sender As System.Object,_
ByVal e As System.EventArgs) Handles Button1.Click
PictureBox1.Image = Image.FromFile("C:\sample.gif")
'loading the image into the picturebox using the FromFile method of the image class
'assuming a GIF image named sample in C: drive
End Sub

For Properties See: Control Object Properties - Form Properties

  Privacy Policy | Terms of Use | Site Map | Contact

  © 2004-2010 Startvbdotnet.com. All rights reserved.