Unit-3-3
Unit-3-3
Properties:
All the .NET Objects can be moved resized or customized by setting their
properties. A property is a value or characteristic held by a .NET object, such as
Caption or ForeColor. Properties can be set at design time by using the Properties
window or at run time by using statements in the program code.
Methods:
A method is a procedure created as a member of a class and they cause an object to
do something. Methods are used to access or manipulate the characteristics of an
object or a variable. There are mainly two categories of methods you will use in
your classes:
If you are using a control such as one of those provided by the Toolbox, you
can call any of its public methods. The requirements of such a method
depend on the class being used.
If none of the existing methods can perform your desired task, you can add a
method to a class.
Events:
An event is a signal that informs an application that something important has
occurred. For example, when a user clicks a control on a form, the form can raise a
Click event and call a procedure that handles the event. There are various types of
events associated with a Form like click, double click, close, load, resize, etc.
FORM:
VB.NET Form is the container for all the controls that make up the user
interface.
Every window you see in a running visual basic application is a form,
adding controls and other items from the toolbox.
In VB.NET, the support for windows forms is in the System.Window.Forms
namespace and the form class is System.Windows.Form.
The form class itself is based on the Control class, which means that forms
share a lot of the properties and methods that control do.
The main area of a form- the area where everything takes place- is called the
client area.
In general, Visual Basic code works with controls in the client area and
leaves the rest of the form to Visual Basic.
Form Properties:
Following lists down various important properties related to a form. These
properties can be set or read during application execution.
AcceptButton: Gets or sets the button on the form that is pressed when the user
uses the Enter key.
ActiveMidChild: Gets the currently active multiple document interface (MDI)
child window.
AllowDrop: Indicates if the form can accept data that the user drags and drops into
it.
AutoScale: Indicates if the form adjust its size to fit the height of the font used on
the formand scales its controls.
AutoScroll: Indicates if the form implements auto scrolling.
BackColor: Gets or sets the background color for this form.
BackgroundImage: Gets or sets the background image in the form.
Bottom: Gets the location of the bottom of the form.
Bounds: Gets or sets the bounding rectangle for the form.
Enabled: Gets or sets a value indicating if the form is enabled.
Focused: Indicates if the form has input focus.
ForeColor: Gets or sets the foreground color of the form.
FormBorderStyle: Gets or sets the border style of the form.
Height: Gets or sets the height of the form.
IsMdiChild: Indicates if the form is an MDI child form.
IsMdiContiner: Gets or sets a value indicating if the form is a container for MDI
child forms.
MaximizeBox: Gets or sets a value indicating if the maximize button is displayed
in the captionbar of the form.
MaximizeSize: Returns the maximum size the form can be resized to.
MdiChildren: Return an array of forms of the MDI child forms that are parented
to this form.
MdiParent: Gets or sets the current MDI parent form of this form.
Menu: Gets or sets the Main Menu that is displayed in the form.
Form Methods:
The following are some of the commonly used methods of the Form class:
GetNextControl Gets the next control in the tab order of child controls.
Form Events:
Windows forms also support events, when you click a form, a click event occurs,
and when the form is closed, a closed event occurs. Following table lists down
various important events related to a form.
Event Description
KeyDown Occurs when a key is pressed while the form has focus.
KeyPress Occurs when a key is pressed while the form has focus.
KeyUp Occurs when a key is released while the form has focus.
Occurs when the mouse pointer is over the form and a mouse
MouseDown
button is pressed.
MouseMove Occurs when the mouse pointer is moved over the form.
Occurs when the mouse pointer is over the form and a mouse
MouseUp
button is released.
Occurs when the mouse wheel moves while the control has
MouseWheel
focus.
Scroll Occurs when the user or code scrolls through the client area.
Property Description
Enabled It is used to specify whether label control is enabled or not at run time.
It has Boolean value. Default value is true.
Image It is used to specify an image that is displayed in Label Control.
ImageAlign It is used to get or set alignment of the image that is displayed in the
Label control.
Text It is used to get or set text associated with the Label control.
TextAlign It is used to get or set alignment of the text associated with the Label
control.
Visible It is used to specify whether label control is visible or not at run time.
It has Boolean value. Default value is true.
Methods:
Method Description
Show It is used to show label control at run time.
Hide It is used to hide label control at run time.
Events:
Event Description
Click It is the default event of Label Control. It fires each time
user clicks on Label Control.
DoubleClick It fires each time user double clicks on Label Control.
TextChanged It fires each a text associated with Label Control is changed.
Example: Program that accepts two numbers from user and performs addition,
subtraction, multiplication and division of two numbers using Label, Textbox
and Button Control.
Source Code:
Public Class Form1
Dim a As Integer
Dim b As Integer
Dim ans As Integer
Text Box:
It is used to accept textual input from the user. The user can add strings,
numerical values and a combination of those, but Images and other
multimedia content are not supported.
By default, it takes a single line of text, however, you can make it accept
multiple texts and even add scroll bars to it. The prefix of TextBox is ―txt‖.
Properties:
Property Description
Name Indicates the name used in code to indentify the object.
Ex. txtname, txtaddress
Text Gets or sets the current text in the TextBox.
Methods:
Method Description
Clear Clears all text from the text box control.
Cut Moves the current selection in the text box to the Clipboard.
Copy Copies the current selection in the text box to the Clipboard.
Paste Replaces the current selection in the text box with the contents of
the Clipboard.
Undo Undoes the last edit operation in the text box.
Focus Sets focus to the TextBox.
ToString() Returns a string that represents the TextBox control.
Events:
Event Description
TextChanged It is the default event of TextBox Control. It fires each time
a text in the TextBox control is changed
GotFocus It fires each time a focus is set on TextBox
LostFocus It fires each time a focus is lost from TextBox
Button:
Button is a widely used control in application. It is used to perform an
action.
Whenever user clicks on a button the click event associated with the
button is fired and the action associated with the event is executed.
The prefix for button control is ―btn‖.
We can set accelerator key for the button. It is also known as mnemonics. It
is represented by underlined characters.
For example set text property of the btnans(button) as &Ans. It will display
underline under the character A now we call btnans button’s event by ALT
+A.
Properties:
Property Description
Name Indicates the name used in code to indentify the object.
Ex. btnans,btnshow.
Text Gets or sets the current text in the Button.
TextAlign It is used for setting text alignment such as
Left,Right,Center
Enabled It is used to specify whether textbox control is enabled or
not at run
time. It has Boolean value. Default value is true.
TabIndex Gets or sets the tab order of the control within its
container.
BackColor It is used to get or set background color.
Font It is used to set Font Face, Font Style, Font Size and Effects
of the text.
Visible It is used to specify whether the control is visible or not at
run time. It
has Boolean value. Default value is true.
FlatStyle It is used to get or set appearance of the Button
Control when user moves mouse on it or click on it. It
has following 4 options:
System, Popup, Standard, Flat
Image It is used to specify an image that is displayed on it.
ImageAlign It is used to get or set alignment of the image that is
displayed on it. control.
TextImageRelation It is used to get or set position of text in relation with
image. It has following 5 options:
(1) Overlay
(2) ImageAboveText
(3) TextAboveImage
(4) ImageBeforeText
(5) TextBeforeImage
It is used when user wants to display both text and image
on Button Control.
Methods:
Method Description
Show It is used to show Button control at run time.
Hide It is used to hide Button control at run time
Events Description
Example:
Source Code:
Public Class btn_ex
Dim a As String
Private Sub btndisplay_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btndisplay.Click
a = MessageBox.Show("Name: " & txtname.Text & vbCrLf & "Password:" &
txtpwd.Text & vbCrLf & "Address:" & txtadd.Text)
End Sub
Checkbox:
It is used to set true/false or yes/no type options. The user can select or
deselect it. When a check box is selected it has the value True, and when it is
deselected, it has the value False.
The prefix of the checkbox is “chk”.
Properties:
Property Description
Text Gets or sets the current text of it.
Appearance It is used to determining the appearance of the check box.
Autocheck When check box is clicked it automatically change state
(True/False). By default
it is true.
CheckAlign It Determine the location of the checkbox inside the control. By
default it is
Middleleft.
Prepared By Prof. Hemanta Bhatt Page 12
SDJ International College, Palsana
Events:
Event Descrption
CheckedChanged Raised when Checked property of the CheckBox control is
changed
Methods:
Methods Description
GetPreferredSize Retrieves the size of a rectangular area into which a control
can be fitted.
NotifyDefault Notifies the Button whether it is the default button so that it
can adjust its appearance accordingly.
Select Activates the control.
ToString Returns a String containing the name of the Component, if
any. This method should not be overridden.
Example:
Source Code:
Public Class chkfrm
End Sub
Radio Button:
It is also known as an option button. We can check one radio button at a
time. Radio button are generally use for one in multiple options like
Gender, Stream etc. We can checked or unchecked the radiobutton.
The prefix of the radiobutton is either “opt” or “rad”.
Properties:
Property Description
Text Gets or sets the current text of it.
TextAlign It is used for setting text alignment such as Left, Right, Center
Appearance It is used to determining the appearance of it (normal or button).
Enabled It is used to specify whether the control is enabled or not at run
time. It has Boolean value. Default value is true.
Visible It is used to specify whether the control is visible or not at run time. It
has Boolean value. Default value is true.
Autocheck When check box is clicked it automatically change state (True/False).
By default it is true.
CheckAlign It Determine the location of the checkbox inside the control. By
default it is Middleleft.
Checked Indicating whether the check box is in checked state (True/False).
Events:
Events Description
AppearanceChanged Occurs when the value of the Appearance property of the
RadioButton control is changed.
CheckedChanged Occurs when the value of the Checked property of the
RadioButton control is changed.
Methods:
Methods Description
Contains The Contains() method is used to check if the defined control
is available in the RadioButton control.
Focus The Focus() method is used to set the input focus to the
window form's RadioButton control.
GetAutoSizeMode It is used to return a value that represents how the control
will operate when the AutoSize property is enabled in the
RadioButton control of the Window form.
Update It is used to reroute an invalid field, which causes control in
Prepared By Prof. Hemanta Bhatt Page 15
SDJ International College, Palsana
Example:
Source Code:
Properties:
Property Description
BackgroundImage It is used to set background Image for the DateTimePicker.
CalendarFont It is used to set the font style for the calendar in the
DateTimePicker control.
CustomFormat It is used to set the custom date and time format string in
the
DateTimePicker control. dd/mm/yy
Checked It is used to check whether the value property is checked
with a valid date and time in the DateTimePicker control.
Format It is used to set the format for the Date and time displayed
in the Windows Form. dd/mm/yyyy
MaxDate It is used to set the maximum date value.
Name Indicates the name used in code to indentify the object.
MinDate It is used to set the minimum date value.
Value The current date and time value for this control.
Events:
Event Description
Click Occurs when the control is clicked.
CloseUp Occurs when the drop-down calendar is dismissed and
disappears.
DoubleClick Occurs when the control is double-clicked.
DragDrop Occurs when a drag-and-drop operation is completed.
ForeColorChanged Occurs when the value of the ForeColor property changes.
FormatChanged Occurs when the Format property value has changed.
Methods:
Method Description
Select It is used to start or activate the DateTimePicker control.
Show It is used to display the control.
ToString It is used to return string that represent date and time.
Example:
Source Code:
List Box:
It is used to display list of items. It allows user to select one or more
items from the listbox.
We can add or design the list box by using the properties and events at
runtime.
It is used for displaying larger number of choices.
A scroll bar is automatically appears when many items in the ListBox.
By default we can select only one item from ListBox.
The Prefix is “lst”.
Properties:
Property Description
Name It represents unique name of control. It is used in the coding.
DataSource It is used to bind a collection of items to a ListBox
DisplayMember It gets or sets the field to be displayed in the ListControl.
Items It gets the items of the ListBox
.
Multicolumn It allows multiple items to be displayed in the ListBox. It
has Boolean Value (True/False). By default it is false.
.
Events:
Event Description
Click It occurs when ListBox is selected
SelectedIndexChanged It occurs when SelectedIndex property is changed
Methods:
Method Description
ClearSelected Unselects all the items in the ListBox.
FindString It returns the index of specified string. If it does not match
then returns -1.
FindStringExact It returns the index of exactly matches of the specified string.
GetSelected It checks whether given index of item is selected or not. It
returns Boolean value. If item is selected then it returns true
otherwise false.
SetSelected It selects or deselects the item of the given index.
Eample:
Source Code:
ListBox1.Items.Clear()
Label3.Text = ListBox1.Items.Count()
End Sub
End Class
Combo Box:
The ComboBox control is used to display a drop-down list of various items.
It is a combination of a TextBox and ListBox.
You can populate the list box items either from the properties window or at
runtime.
User can select only one item from the given list.
Combo Box has three different Drop Down style: Simple, drop down and
drop-down list
The prefix of ComboBox is “cmb”.
Properties:
Property Description
DataBindings It gets the data binding for the control.
Name It represents unique name of control. It is used in the
coding.
DataSource It is used to bind a collection of items to a ComboBox
DisplayMember It gets or sets the field to be displayed in the
ComboBox.
ValueMember It is used to get or set the actual value for the items in
the control.
Items It gets the items of the ComboBox.
.
SelectedIndex It returns the index of the selected item. If more than
one item is selected, it represents the lowest index. If no
item is selected then it returns -1.
SelectedItem It returns the text of selected item. If more than one item
is selected, then it returns the 1st Selected Item.
SelectedText Gets or sets the text that is selected in the editable
portion of a ComboBox
SelectedValue Gets or sets the value of the member property specified
by the ValueMember property.
Sorted Gets or sets a value indicating whether the items in the
combo box are sorted.
IntegralHeight Indicates whether the combo box should resize to
avoid showing partial items.(true(Default)/false)
Methods:
Method Description
SelectAll Selects all the text in the editable area of the combo box.
FindString It returns the index of specified string. If it does not match then
returns -1.
FindStringExact It returns the index of exactly matches of the specified string.
Events:
Event Description
SelectedIndexChanged It occurs when SelectedIndex property is changed
Example: Program to get the selected items in the combo box and show them in a
list box and sort the items.
Source Code:
Public Class cmb_box
Picture Box:
It is used for displaying images on the form. The Image property of the
control allows you to set an image both at design time and at run time.
Properties:
Property Description
Name It represents unique name of control. It is used in the
coding.
Image Gets or sets the image that is displayed in the control.
SizeMode Determines the size of the image to be displayed in the
control. This property takes its value from the
PictureBoxSizeMode enumeration, which has values −
Normal − the upper left corner of the image is
placed at upper left part of the picture box
StrechImage − allows stretching of the image
AutoSize − allows resizing the picture box to
the size of the image
CenterImage − allows centering the image in the
picture box
Zoom − allows increasing or decreasing the
image size to maintain the size ratio.
Height Gets or sets the height of the image
Width Gets or sets the width of the image
Events:
Events Description
Click Occurs when the control is clicked.
FontChanged Occurs when the value of the Font property changes.
Enter Overrides the Control.Enter property.
ForeColorChanged Occurs when the value of the ForeColor property changes.
Methods:
Methods Description
Load Displays an image in the picture box
ToString Returns the string that represents the current picture box.
Example:
Source Code:
Public Class Form1
Properties:
Property Description
Text Gets or sets current text of the control.
SelectionAlignment Gets or sets the Alignment to apply to current selection
SelectionBackColor Gets or sets background color of text.
SelectionBullet Gets or sets bullet list
SelectionFont Gets or sets font of current selection
SelectionColor Gets or sets text color of the current text selection.
SelectedText Gets or sets the selected text
ZoomFactor Define the scaling factor of it.
Methods:
Method Description
AppendText Appends text to the end of the control's text.
Cut Cuts the selected text to the Clipboard.
Copy Copies the selected text to the Clipboard.
Paste Replaces the current selection in the text box with the
contents of the
Clipboard
Undo Undoes the last edit operation in the control.
Find Finds the specified text within the control.
LoadFile Loads the contents of a file into the control.
SaveFile Saves the contents of the control to a file.
Clear Clears all text from the control.
Events:
Events Description
Click Triggered when control is clicked.
LinkClick Triggered when user clicks on the link within the text.
Selectionchanged Triggered when selection property is changed.
VScroll Occurs when vertical scroll bars are clicked.
Example:
Source Code:
Public Class Form1
Dim a, b As Integer
Dim str As String
Private Sub btndisplay_Click(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles btndisplay.Click
a = Val(txtfirst.Text)
b = Val(txtsecond.Text)
For i = 1 To 10
For j = a To b
RichTextBox1.AppendText(String.Format(" {0} * {1} =
{2} ", j, i, (j * i).ToString().PadRight(10)))
Next
RichTextBox1.AppendText(vbCrLf)
Next
End Sub
End Class
Tree View:
It is a powerful tool that allows you to display hierarchical data in a tree
structure. The control can be used to display a variety of data, including files
and folders, organizational charts, family trees, and more.
It is collection of nodes. The main starting node is called root node. Under
the root, a real tree is made of branches and leaves. A node can have a node
as a child. We can expand and collapse these nodes by clicking them.
Tree view has nodes collection.
Methods:
Method Description
Add It adds nodes in the Tree view
Clear It clear all the nodes from the Tree view
Contains It checks whether the given node is a part of Tree view or not.
It returns Boolean value.
Insert We can insert node in the Tree View in any place by using this
method. It contains two arguments. Index and node.
Remove It removes the node from the Tree View. The argument of Remove ()
method is the node.
RemoveAt It removes the node from the Tree View by index.
TopNode It is used to get or set full visible tree nodes on top of other
nodes in the tree view control.
VisibleCount It is used to obtain the fully visible tree node in the tree view
control.
ItemHeight The ItemHeight property is used to set the height of each tree
node in control.
Scrollable The Scrollable property is used in the tree-view to display the
scroll bar by setting the value in control.
Methods:
Method Description
ExpandAll() As the name suggests, an ExpandAll method is used to
expand all the tree nodes.
CollapseAll It is used to collapse all tree nodes, including all child
nodes in the tree view control.
Sort() A Sort method is used to sort the tree nodes that are
available in the tree view control.
GetNodeCount It is used to count the number of nodes that are available in
the tree view control.
ToString ToString method is used to return the name of the string that
is in the tree view control.
Example:
Source Code:
Public Class frmtreeview
Sub filltreeview()
TreeView1.Nodes.Add("Database") 'this is root node
TreeView1.Nodes(0).Nodes.Add("sql server")
TreeView1.Nodes(0).Nodes.Add("my sql")
TreeView1.Nodes(0).Nodes.Add("Oracle")
TreeView1.Nodes.Add("Programming langauage") 'this is root node
TreeView1.Nodes(1).Nodes.Add("C#")
TreeView1.Nodes(1).Nodes.Add("VB")
TreeView1.Nodes(1).Nodes.Add("Java")
End Sub
End Sub
Tool Tip:
A tooltip is a small pop-up window that displays some information when
you rollover on a control.
Tooltip class represents a tooltip control. Once a Tooltip object is
created, we need to call SetToolTip method and pass a control and text.
Properties:
Property Description
Active A tooltip is currently active.
AutomaticDelay Automatic delay for the tooltip.
AutoPopDelay The period of time the ToolTip remains visible if the
pointer is stationary on a control with specified ToolTip
text.
InitialDelay Gets or sets the time that passes before the ToolTip
appears.
IsBaloon Gets or sets a value indicating whether the ToolTip
should use a balloon window.
ReshowDelay Gets or sets the length of time that must transpire before
subsequent ToolTip windows appear as the pointer moves
from one control to another.
ShowAlways Displays if tooltip is displayed even the parent control is
not active.
ToolTipIcon Icon of tooltip window.
Methods:
Events Description
GetToolTip Returns a tool tip text.
SetToolTip Connects tool tip text with the tool tip.
Example:
Source Code:
Public Class Form1
Progress Bar:
It is used to graphically display the progress of particular task. Thus using
Progress Bar control you can display how much task has been completed
and how much task is remaining.
It shows the progress of any background activity. It is a good idea to show
the progress to the end user when an application is performing complex or
time consuming background tasks.
Properties:
Property Description
Minimum It Get or Set Lower Bound of the range
within which ProgressBar Control works.
Maximum It Get or Set Upper Bound of the range within which
ProgressBar Control works.
Value It Get or Set current value of the ProgressBar within
range specified using Minimum and Maximum
property.
Step It Get or Set Step value by which the current value of
ProgressBar control is Increment.
Style It is used to set the Style of ProgressBar Control. It
can have one of the following value: Blocks,
Continuous, Marquee.
Visible It is used to set weather ProgressBar control is visible
on the form or not. It has boolean value true or false.
Default value is true.
Enabled It is used to set weather ProgressBar control is
enabled or not. It has boolean value true or false.
Default value is true.
MarqueeAnimationSpeed It Get or Set speed of marquee animation when Style
property of ProgressBar Control is set to marquee.
The speed is in milisecond. Default value is 100 ms.
Methods:
Methods Description
Increment It is used to increment the current value of ProgressBar
Control by specific value.
Syntax: ProgressBar1.Increment(value)
PerformStep It is used to increment the current value of ProgressBar
Control by the value specified in the Step property of
ProgressBar.
Syntax:progressBar1.PerformStep()
Example:
Source Code:
Public Class Form1
Dim a As Integer
Private Sub btnstart_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles btnstart.Click
Timer1.Enabled = True
ProgressBar1.Maximum = 100
'a = 1
End Sub
Properties:
Property Description
Mask It is used to get or set format string which determines
whether characters entered in MaskedTextBox are valid or not.
AllowPromptAsI It is used to specify whether Prompt character can be entered
nput as valid input character in MaskedTextBox or not. It has
Boolean value. Default value is true.
AsciiOnly It is used to specify whether only ASCII characters can be
entered as valid input character in MaskedTextBox or not. It
has Boolean value. Default value is false.
BeepOnError It is used to specify whether control will generate system
beep sound on each invalid character input or not. It has
Boolean value. Default value is false.
Prepared By Prof. Hemanta Bhatt Page 37
SDJ International College, Palsana
Methods:
Method Purpose
Append Text It is used to append text at the end of current text in it.
Clear It is used to clear all text from it.
Cut It is used to move current selection of it into clipboard.
Copy It is used to copies selected text of it into clipboard.
Paste It is used to replace current selection of MaskedTextBox by
contents of clipboard. It is also used to move contents of
Clipboard to MaskedTextBox control where cursor is currently
located.
Select It is used to select specific text from it.
SelectAll It is used to select all text of it.
DeselectAll It is used to deselect all text selected in it.
Show It is used to show the control at run time.
Hide It is used to hide the control at run time.
Focus It is used to set input focus on the control at run time.
Events:
Event Description
MaskChanged It fires each time a mask property is changed.
TextChanged It fires each time a text in the MaskedTextBox control changed.
Example:
Notify Icon:
It is used to add system tray notification functionality to a Windows Forms
application.
When an application is run, an icon will be added to the system tray and we
can add double click or menus to the icon to take some actions.
Properties:
Property Description
Icon Set the icon for the NotifyIcon.
ContentMenuStrip The short cut menu to show when the user right clicks the
icon.
Text Get or set tool tip text when mouse hovers the icon.
Visible Used to make the icon visible or invisible.
Methods:
Methods Description
Dispose Releases all resources used by the Component.
GetType Gets the Type of the current instance.
Prepared By Prof. Hemanta Bhatt Page 39
SDJ International College, Palsana
Events:
Events Description
BalloonTipClicked Occurs when the balloon tip is clicked.
Click Occurs when the user clicks the icon in the notification area.
DoubleClick Occurs when the user double-clicks the icon in the
notification area of the taskbar.
MouseUp Occurs when the user releases the mouse button while the
pointer is over the icon in the notification area of the taskbar.
MouseDown Occurs when the user presses the mouse button while the
pointer is over the icon in the notification area of the taskbar.
Link Label:
It is similar to Label control, but it can display a hyperlink.
Multiple hyperlinks can be specified in the Text of the control.
Each hyperlink can perform a different task within an application.
Properties:
Property Description
AutoSize Gets or sets a value indicating whether the control automatically
adjusts its size to fit its contents.
LinkArea Gets or sets the area of the control that is treated as a link.
LinkBehavior Gets or sets a value that specifies the behavior of the link.
Links Gets the collection of links in the control
LinkColor Gets or sets the color used for links in the control.
Text Gets or sets the text displayed by the control.
Methods:
Method Description
DoDragDrop Initiates a drag-and-drop operation.
Focus Sets input focus to the control.
OnLinkClicked Raises the LinkClicked event.
ToString Returns a string representation of the control.
Events:
Event Description
LinkClicked Triggered when the link is clicked.
Example:
Source Code:
Public Class linklabel
Properties:
Property Description
Items It gets or sets the items contained in the CheckedListBox
control.
CheckedItems It gets a collection of the checked items in the
CheckedListBox control.
CheckedIndices It gets a collection of the indices of the checked items in the
CheckedListBox control.
CheckOnClick It gets or sets a value indicating whether the checkboxes are
automatically checked or unchecked when the item is
clicked.
SelectionMode It gets or sets a value indicating whether the user can select
multiple items or only one item.
ThreeState It gets or sets a value indicating whether the checkboxes
have three states: checked, unchecked, and indeterminate.
DisplayMember It gets or sets the property to display for each item in the
CheckedListBox control.
ValueMember It gets or sets the property to use as the actual value of each
item in the CheckedListBox control.
DataSource It gets or sets the data source for the CheckedListBox
control.
ScrollAlwaysVisible It gets or sets a value indicating whether the vertical
scrollbar is always visible or not.
Method:
Method Description
SetItemChecked(index, It sets the check state of the item at the specified index
value) in the CheckedListBox control to the specified value.
GetItemChecked(index) It gets the check state of the item at the specified index
in the CheckedListBox control.
GetItemCheckState(inde It gets the check state of the item at the specified index
x) in the CheckedListBox control and returns it as
CheckState enumeration value.
SetItemCheckState(index It sets the check state of the item at the specified
, state) index in the CheckedListBox control to the specified
CheckState enumeration value.
GetItemText(index) It gets the text of the item at the specified index in the
CheckedListBox control.
FindStringExact(value) It searches for the item with the specified text and
returns the index of the first item found.
FindStringExact( It searches for the item with the specified text,
value, startIndex) starting from the specified index, and returns the
index of the first item
Events:
Event Description
SelectedIndexChanged It occurs when SelectedIndex property is changed
Example:
Source Code:
Public Class Form1
End Sub
End Sub
End Class
1. Group Box:
A GroupBox control is a container control that is used to place Windows
Form child controls in a group.
The purpose of GroupBox control is to define user interfaces where we can
categories related control in a group.
Property:
Text: It is used to specify the caption of the displayed GroupBox control.
Event:
Enter: Occurs when the mouse is entered.
Methods:
OnEnter: It raises Enter event.
2. Panel:
It is used to group collections of controls.
By default, the panel control is displayed without borders.
Have the capacity to scroll by setting its AutoScroll property to True.
Property:
Property Description
Enabled It gets or set a value indicating whether the control can
Methods:
Methods Description
AdjustFromScrollbars It adjusts the scroll bars on the container based on the
current control positions and currently selected control.
GetScrollState It determines whether the specified flag has been set.
SetScrollState It sets the specified scroll state flag.
SetAutoScrollMargin It sets the size of the auto-scroll margins.
Event:
Paint()
3. TabControl:
It contains tab pages which are represented by TabPage objects.
The order of Tab pages in this collection reflects the order of the tabs appear
in the control.
The user can change the currents TabPage by clicking one of the tabs in the
control.
It manages a related set of tab pages.
Properties:
Property Description
Alignment It gets or sets area of control where the tabs are aligned.
Appearance It gets or sets visual appearance of the selected tab of control.
ImageList It gets or sets images to display on the tabs.
ImageSize It gets or sets image size of the tabs.
MultiLine It gets or sets indicating whether more than on row of tabs can
be displayed.
TabPages It gets the collection of tab pages in tab control.
TabCount It gets the number of tab pages in tab control.
Methods:
Methods Description
DeselectTab It deselects the tab control.
RemoveAll It removes all the tab pages and additional controls from this
tab control.
SelectTab It makes the tab with the specified index as current tab.
4. SplitContainer:
It represents a control consisting of a movable bar that divides a display area
of a container into two resizable panels.
You can add controls to the two resizable panels, and you can add other
SplitContainer controls to existing Splitcontainer panels to create many
resizable display areas.
When the user passes the mouse pointer over splitter, the cursor changes,
which indicates that the controls inside the SplitContainer control can be
resized.
Exmaple:
5. FlowLayout Panel:
It represents a panel that dynamically lays out its contents horizontally or
vertically.
It contents can be wrapped from one row to the next or from one column to
the next.
Alternatively, its contents can be clipped instead of wrapped.
6. TableLayout Panel:
It representes a panel that dynamically lays out its contents in a grid
composed of and columns.
Margin, DefaultPadding, Padding properties of TableLayout panel is similar
to FlowLayout panel.
1. ImageList:
It is a simple control that stores images used by other controls at runtime.
Properties:
Property Description
Images Gets the collection of images in the image list.
Prepared By Prof. Hemanta Bhatt Page 48
SDJ International College, Palsana
ColorDepth Gets or sets the color depth of the images in the image
list.
TransparentColor Gets or sets the color that is treated as transparent.
ImageSize Gets or sets the size of the images in the image list.
Tag Gets or sets an object that contains data about the control.
Methods:
Method Description
Clear Removes all the images from the image list.
Add Adds a new image to the image list, using the specified key to
identify it.
IndexOfKey Returns the index of the image with the specified key.
RemoveByKey Removes the image with the specified key from the image list.
Disposed Occurs when the control is disposed of by a call to the Dispose
method.
ItemAdded Occurs when an item is added to the image list.
ItemRemoved: Occurs when an item is removed from the image list.
Example:
Source Code:
Public Class Form1
Dim n As Integer = 0
2. ErrorProvider:
ErrorProvider allows us to set an error message for any control on the form
when the input is not valid.
When an error message is set, an icon indicating the error will appear next to
the control and the error message is displayed as Tool Tip when the mouse
is over the control.
Properties:
Property Description
Name It is used to specify name of ErrorProvider Control.
BlinkRate It is used to specify rate in milisecond at which error icon
blinks.
BlinkStyle It is used to specify Blink Style for Error Icon. It can be:
AlwaysBlink, NeverBlink, BlinkIfDifferentError
Icon It is used to specify ICON to be displayed near to the control
when error is set for that control.
Methods:
Method Description
SetError It is used to set error message for particular control.
Ex:ErrorProvider1.SetError(ControlName,"ErrorMessage")
GetError It is used to retrieve current error message of particular control.
Ex: ErrorProvider1.GetError (ControlName).
Clear It is used to clear all the settings of ErrorProvider Control.
Ex:ErrorProvider1.Clear()
Example:
Source Code:
Public Class Form1
Private Sub btnchk_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnchk.Click
If Not IsNumeric(TextBox1.Text) Or Not TextBox1.Text.Length = 10 Then
ErrorProvider1.SetError(TextBox1, "Please Enter Only 10 Digit
Number")
Else
ErrorProvider1.SetError(TextBox1, "")
MsgBox(TextBox1.Text)
End If
End Sub
End Class
3. HelpProvider:
This control provides pop-up or online help for controls.
HelpProvider control provides help with your application is very useful as it
allows users to understand it more easily.
Properties:
Property Description
HelpNamspace Gets or sets a value specifying the name of the Help file
associated with this HelpProvider.
Methods:
Methods Description
SetShowHelp It specifies whether Help is displayed for the specified
control.
SetHelpString It specifies the Help string associated with the specified
control.
SetHelpNavigator It specifies the Help command to use when retrieving
Help from the Help file for the specified control.
SetHelpKeyword It specifies the keyword used to retrieve Help when the
user invokes Help for the specified control.
4. Timer:
It is used when user wants to perform some task or action continuously at
regular interval of time.
Properties:
Property Description
Name It is used to specify name of the Timer Control.
Enabled It is used to determine whether Timer Control will be enable
or not. It has Boolean value true or false. Default value is
false.
Interval It is used to specify interval in millisecond. Tick event of
Timer Control generates after the time which is specified in
Interval Property.
Methods:
Methods Description
Start This method is used to start the Timer Control.
Stop This method is used to stop the Timer Control.
Events:
Events Description
Tick Tick event of the Timer Control fires continuously after the
time which is specified in the Interval property of Timer
Control.
Source Code:
Public Class Form1
Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Timer1.Tick
If OvalShape1.Visible Then
OvalShape1.Visible = False
OvalShape2.Visible = True
OvalShape3.Visible = False
ElseIf OvalShape2.Visible Then
OvalShape1.Visible = False
OvalShape2.Visible = False
OvalShape3.Visible = True
ElseIf OvalShape3.Visible Then
OvalShape1.Visible = True
OvalShape2.Visible = False
OvalShape3.Visible = False
End If
End Sub
OvalShape3.Visible = False
End Sub
End Class
MenuStrip:
The MenuStrip control represents the container for the menu structure.
Let us add menu and sub-menu items. Perform the following steps:
Drag and drop or double click on a MenuStrip control, to add it to the form.
Click the Type Here text to open a text box and enter the names of the
menu items or sub-menu items you want. When you add a sub-menu,
another text box with 'Type Here' text opens below it.
Complete the menu structure shown in the diagram above.
Add a sub menu Exit under the File menu.
Properties:
Property Description
CanOverflow The CanOverflow property is used to authenticate
whether the control supports overflow functionality by
setting values in the MenuStrip control.
Stretch The Stretch property is used to obtain a value that
specifies whether the menustrip stretches from end to end
in the MenuStrip control.
GripStyle The GripStyle property obtains or sets the visibility of the
grip that uses the reposition of the menu strip control.
ShowItemToolTips It is used to obtain or set the value that determines if the
ToolTips are displayed for the MenuStrip Control.
DefaultSize The DefaultSize property is used to get the default
horizontal and vertical dimension of the MenuStrip in
pixel when it is first created.
Methods:
Methods Description
CreateAccessibilityInstance() It is used to create a new accessibility instance for
the MenuStrip Control.
ProcessCmdKey() The ProcessCmdKey method is used to process
the command key in the MenuStrip Control.
CreateDefaultItem() The CreateDefaultItem method is used to create a
ToolStripMenuItem with the specified text,
image, and event handlers for the new MenuStrip.
OnMenuActivate() It is used to initiate the MenuActivate event in the
MenuStrip control.
OnMenuDeactivate() It is used to start the MenuDeactivate event in the
MenuStrip control.
Events:
Events Description
MenuActivate When a user uses a menu bar control with a mouse or
keyboard, a MenuActivate event occurs.
MenuDeactivate The MenuDeactivate event occurs when the MenuStrip control
is deactivated in the Windows form.
ContextMenuStrip:
Menu items which are available when you right click are called Context
Menus.
Steps of Context Menu:
Drag and drop context menu strip control to the textbox control.
When you do, you will notice two things. At the top of your form, you will
see this. And type cut copy and paste options. Then set the
ContextMenuStrip Property of the object.
At the bottom of the page set the ContextMenuStrip property of the object.
Properties:
Properties Description
SourceControl Gets the last control that displayed the ContextMenuStrip
control.
AllowTransparency It gets or sets value indicating whether the opacity of the
form can be adjusted.
Opacity It determines the opacity of the form.
OwnerItem It gets or sets the Item that is owner of this DropDown.
TopMost It gets or sets a value indicating whether the form should be
displayed as a topmost form.
Methods:
Methods Description
Close It closes the control.
Show It displays the control on its default position.
ToolStrip:
It provides a container for Windows toolbar objects.
ToolStrip is the base class for MenuStrip, ContextMenuStrip and
StatusStrip.
It can contain Button, Seperator, Label, DropDownButton, SplitButton,
TextBox and ComboBox.
StatusStrip:
It represents a windows status bar.
It can contain Status Label, DropDownButton, SplitButton and ProgressBar.
It displays information about an object being viewed on a Form, or
information that relates to that operation of the object within your
application.
ToolStrip Container:
It provides panels on each side of the form and a central panel that can hold
one or more control.
It similar to SplitContainer.
It uses four docked side panels one central panel to create a typical
arrangement.
Dialog Boxes:
VB.Net contains built-in dialog boxes which allow user to create our own
Open, Save, Font and Color dialogs control that are similar to other
windows applications.
The common dialog controls are as follows:
1. OpenFileDialog
2. SaveFileDialog
3. FontDialog
4. ColorDialog
5. PrintDialog
6. PrintPriviewDialog
7. PageSetupDialog
8. FolderBrowserDialog
1. OpenFileDialog:
The OpenFileDialog control prompts the user to open a file and allows the
user to select a file to open.
The user can check if the file exists and then open it.
The OpneFileDialog conrtol class inherits from the abstract class
FileDialog.
Properties:
Properties Description
AddExtension Gets or sets a value indicating whether the dialog box
automatically adds an extension to a file name if the user omits
the extension.
CheckFileExists Gets or sets a value indicating whether the dialog box displays
a warning if the user specifies a file name that does not exist.
DefaultExt Gets or sets the default file name extension.
Prepared By Prof. Hemanta Bhatt Page 60
SDJ International College, Palsana
CustomPlaces Gets the custom places collection for this FileDialog instance.
FileName Gets or sets a string containing the file name selected in the
file dialog box.
FileNames Gets the file names of all selected files in the dialog box.
Filter Gets or sets the current file name filter string, which
determines the choices that appear in the "Save as file type" or
"Files of type" box in the dialog box.
Title Gets or sets the file dialog box title.
Methods:
Methods Description
OpenFile Opens the file selected by the user, with read-only permission.
The file is specified by the FileName property.
Reset Resets all options to their default value.
2. SaveFileDialog:
The SaveFileDialog control prompts the user to select a location for saving a
file and allows the user to specify the name of the file to save data.
The SaveFileDialog control class inherits from the abstract class FileDialog.
3. FontDialog:
It prompts the user to choose a font from among those installed on the local
computer and lets the user select the font, font size, and color.
It returns the Font and Color objects.
Properties:
Property Description
AllowVectorFonts Gets or sets a value indicating whether the dialog box
allows vector font selections.
AllowSimulations Gets or sets a value indicating whether the dialog box
allows graphics device interface (GDI) font simulations.
Color Gets or sets the selected font color.
AllowVerticalFonts Gets or sets a value indicating whether the dialog box
displays both vertical and horizontal fonts, or only
horizontal fonts.
Font Gets or sets the selected font.
FontMustExist Gets or sets a value indicating whether the dialog box
specifies an error condition if the user attempts to select a
font or style that does not exist.
MaxSize Gets or sets the maximum point size a user can select.
MinSize Gets or sets the minimum point size a user can select.
Methods:
Method Description
Reset Resets all options to their default values.
RunDialog When overridden in a derived class, specifies a common dialog
box.
ShowDialog Runs a common dialog box with a default owner.
Event:
Event Description
Apply Occurs when the Apply button on the font dialog box is clicked.
4. ColorDialog:
The ColorDialog control class represents a common dialog box that displays
available colors along with controls that enable the user to define custom
colors.
It lets the user select a color.
Properties:
Property Desscription
AllowFullOpen Gets or sets a value indicating whether the user can use the
dialog box to define custom colors.
AnyColor Gets or sets a value indicating whether the dialog box displays
all available colors in the set of basic colors.
CanRaiseEvents Gets a value indicating whether the component can raise an
event.
Color Gets or sets the color selected by the user.
CustomColors Gets or sets the set of custom colors shown in the dialog box.
FullOpen Gets or sets a value indicating whether the controls used to
create custom colors are visible when the dialog box is opened.
SolidColorOnly Gets or sets a value indicating whether the dialog box will
restrict users to selecting solid colors only.
Methods:
Method Description
Reset Resets all options to their default values, the last selected color
to black, and the custom colors to their default values.
RunDialog When overridden in a derived class, specifies a common dialog
box.
ShowDialog Runs a common dialog box with a default owner.
Events:
Event Description
HelpRequest Occurs when the user clicks the Help button on a common
dialog box.
5. PrintDialog:
The PrintDialog control lets the user to print documents by selecting a
printer and choosing which sections of the document to print from a
Windows Forms application.
There are various other controls related to printing of documents. Let us have a
brief look at these controls and their purpose. These other controls are:
Properties:
Property Description
AllowCurrentPage Gets or sets a value indicating whether the Current
Page option button is displayed.
AllowPrintToFile Gets or sets a value indicating whether the Print to
file check box is enabled.
AllowSelection Gets or sets a value indicating whether
the Selection option button is enabled.
AllowSomePages Gets or sets a value indicating whether the Pages option
button is enabled.
Document Gets or sets a value indicating the PrintDocument used to
obtain PrinterSettings.
PrinterSettings Gets or sets the printer settings the dialog box modifies.
PrintToFile Gets or sets a value indicating whether the Print to
file check box is selected.
Methods:
Method Description
Reset Resets all options to their default values.
RunDialog When overridden in a derived class, specifies a common dialog
box.
ShowDialog Runs a common dialog box with a default owner.
Example:
Source Code:
Public Class Form1
Error:
Error means bug which means when you compile or run a program, abnormal
situation may raise, it is known as error.
There are different types of errors:
1. Syntax Error: The error raised by misspelled keywords or variable is called
syntax error. Compiler will normally catch these errors while you are coding
or after compilation of the program.
2. Logical Error: Due to mistake present in sequence of statement, code does
not act as expected. This type of error is called logical error.
3. Runtime error: The error which occurs when the code is executing is
called runtime error.
Exception Handling:
Exception Handling is an in-built mechanism in .Net framework to detect
and handle run time error.
The .Net framework contains lots of standard exception. The exceptions are
something different that occur during the execution of a program. They can
be because of user, logic or system errors.
If a programmer do not provide a mechanism to handle these errors the
program’s execution is terminates.
All the exceptions are directly or indirectly inherited from the Exception
class.
Syntax:
Try
[ tryStatements ]
[ Exit Try ]
[ Finally
[ finallyStatements ] ]
End Try
Try: It is used to identify the code block for which a specific exception will be
activated. It is follow by one or more catch blocks.
Catch: Catching of the Exception is done in this block. It is an exception
handler in which the Exception is handled.
The following table provides some of the predefined exception classes derived
from the Sytem.SystemException class –
Example:
Source Code:
Public Class Form1
Try
Dim no1, no2 As Integer, ans As Integer
no1 = TextBox1.Text
no2 = TextBox2.Text
Catch ex As Exception
Finally
MsgBox("Hello from Finally", MsgBoxStyle.Information,
"Addition")
End Try
End Sub
End Class
GoTo line | Label—Calls the error-handling code that starts at the line
specified at line. Here, line is a line label or a line number. If a runtime error
occurs, program execution goes to the given location. GoTo 0—Disables the
enabled error handler in the current procedure and reset it to nothing. It clears
the error object.
Example:
On Error Go to Label:
Help:
On Error GoTo 0:
Dim n, m, ans As Integer
Help:
On Error GoTo 0
MsgBox("Program completed")