Unit 3 - Visual Programming Material
Unit 3 - Visual Programming Material
PROGRESSBAR CONTROL
It is used to provide visual feedback to your users about the status of some task. It shows a bar
that fills in from left to right as the operation progresses.
The main properties of a progress bar are Value, Maximum and Minimum. The Minimum and
Maximum properties are used to set the minimum and maximum values that the progress bar can
display. The Value property specifies the current position of the progress bar.
The ProgressBar control is typically used when an application performs tasks such as copying
files or printing documents. To a user the application might look unresponsive if there is no
visual cue. In such cases, using the ProgressBar allows the programmer to provide a visual status
of progress.
The following are some of the commonly used properties of the ProgressBar control –
ProgressBar1.Minimum = 0
ProgressBar1.Maximum = 100
ProgressBar1.Value = 0
End Sub
End Sub
Application.Exit()
End Sub
End Sub
End Class
Output
TIMER CONTROL
The timer control is a looping control used to repeat any task in a given time interval.
Furthermore, if we want to execute an application after a specific amount of time, we can use the
Timer Control.
The Timer Control offers precise program control at various time intervals, ranging from
milliseconds to hours. It grants us the ability to configure the Interval property, which operates in
milliseconds (where 1 second equals 1000 milliseconds). For instance, if we desire an interval of
two minutes, we can set the Interval property value to 120000, which represents 120 multiplied
by 1000.
The Timer Control starts its functioning only after its Enabled property is set to True, by default
Enabled property is False.
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Timer1.Start()
End Sub
OUTPUT
CHECKBOX
CheckBox Control. The CheckBox control allows the user 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 cleared, it holds the value False.
OUTPUT
RADIO BUTTON
The RadioButton control is used to provide a set of mutually exclusive options. The user can
select one radio button in a group. If you need to place more than one group of radio buttons in
the same form, you should place them in different container controls like a GroupBox control.
OUTPUT
DIFFERENCE BETWEEN RADIO BUTTON AND CHECK BOX
GROUP BOX CONTROLS
The GroupBox displays a frame around a group of controls with or without a caption. Use a
GroupBox to logically group a collection of controls on a form. The group box is a container
control that can be used to define groups of controls.
Windows Forms GroupBox controls are used to group other controls. There are three reasons to
group controls:
To create a visual grouping of related form elements for a clear user interface.
To create programmatic grouping (of radio buttons, for example).
For moving the controls as a unit at design time.
Example
CHECKBOX CONTROL
The CheckBox control allows the user 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 cleared, it holds
the value False.
Let's create two check boxes by dragging CheckBox controls from the Toolbox and dropping on
the form
The CheckBox control has three states, checked, unchecked and indeterminate. In the
indeterminate state, the check box is grayed out. To enable the indeterminate state, the
ThreeStateproperty of the check box is set to be True.
Example
In this example, let us add four check boxes in a group box. The check boxes will allow the users
to choose the source from which they came to know about the organization. If the user chooses
the check box with text "others", then the user is asked to specify and a text box is provided to
give input. When the user clicks the Submit button, he/she gets an appropriate message.
The Checked property of the radio button is used to set the state of a radio button. You can
display text, image or both on radio button control. You can also change the appearance of the
radio button control by using the Appearance property.
The following are some of the commonly used properties of the RadioButton control −
1 Appearance
Gets or sets a value determining the appearance of the radio button.
2 AutoCheck
Gets or sets a value indicating whether the Checked value and the appearance
of the control automatically change when the control is clicked.
3 CheckAlign
Gets or sets the location of the check box portion of the radio button.
4 Checked
Gets or sets a value indicating whether the control is checked.
5 Text
Gets or sets the caption for a radio button.
6 TabStop
Gets or sets a value indicating whether a user can give focus to the
RadioButton control using the TAB key.
The following are some of the commonly used methods of the RadioButton control −
PerformClick
1
Generates a Click event for the control, simulating a click by a user.
The following are some of the commonly used events of the RadioButton control −
AppearanceChanged
1
Occurs when the value of the Appearance property of the RadioButton
control is changed.
CheckedChanged
2
Occurs when the value of the Checked property of the RadioButton control is
changed.
LISTBOX CONTROL
The ListBox represents a Windows control to display a list of items to a user. A user can select
an item from the list. It allows the programmer to add items at design time by using the
properties window or at the runtime. Let's create a list box by dragging a ListBox control from
the Toolbox and dropping it on the form
The following are some of the commonly used properties of the ListBox control −
The following are some of the commonly used methods of the ListBox control −
The following are some of the commonly used events of the ListBox control −
ListBox1.Items.Add(TextBox1.Text)
End Sub
MessageBox.Show(ListBox1.SelectedItem.ToString())
End Sub
End Class
OUTPUT
PANEL
Panels enhance all of the other layout features discussed so far because they can act as a
container for other controls, much like a form does. Because they are containers, panels have
their own DockPadding property and all of the auto-scroll features described for forms. A control
can be placed into a panel and anchored to the bottom-right corner of that panel, while the panel
itself was docked or anchored to a specific location on a form. By combining panelswith forms,
you can design more complicated layouts that still support resizing. Panels are used in several of
the examples in the next section.
A large control, such as TextBox ,ListBox , or DataGrid , needs to resize properly on a Form
with two buttons (OK and Cancel)
The Panel control works as a container for other controls on the page.
1. To add a Panel to your form, drag a Panel from the toolbox onto the surface of the form
designer.
2. In the Properties section in Visual Studio change the property of Panel .
3. Drag another control from the toolbox and place it on the panel.
4. Click F5 to start the application.
PICTURE BOX CONTROL
The Picture Box control is used for displaying images on the form. The Image property of the
control allows you to set an image both at design time or at run time.
Let's create a picture box by dragging a PictureBox control from the Toolbox and dropping it on
the form.
The following are some of the commonly used properties of the PictureBox control −
Example
End Class
TREE VIEW CONTROL
The TreeView control is used to display hierarchical representations of items similar to the ways
the files and folders are displayed in the left pane of the Windows Explorer. Each node may
contain one or more child nodes.
Let's click on a TreeView control from the Toolbox and place it on the form.
The following are some of the commonly used properties of the TreeView control −
BackColor
1
Gets or sets the background color for the control.
BackgroundImage
2
Gets or set the background image for the TreeView control.
BackgroundImageLayout
3
Gets or sets the layout of the background image for the TreeView control.
BorderStyle
4
Gets or sets the border style of the tree view control.
CheckBoxes
5 Gets or sets a value indicating whether check boxes are displayed next to the
tree nodes in the tree view control.
DataBindings
6
Gets the data bindings for the control.
Font
7
Gets or sets the font of the text displayed by the control.
FontHeight
8
Gets or sets the height of the font of the control.
ForeColor
9 The current foreground color for this control, which is the color the control
uses to draw its text.
ItemHeight
10
Gets or sets the height of each tree node in the tree view control.
Nodes
11
Gets the collection of tree nodes that are assigned to the tree view control.
PathSeparator
12
Gets or sets the delimiter string that the tree node path uses.
RightToLeftLayout
13 Gets or sets a value that indicates whether the TreeView should be laid out
from right-to-left.
Scrollable
14 Gets or sets a value indicating whether the tree view control displays scroll
bars when they are needed.
SelectedImageIndex
15 Gets or sets the image list index value of the image that is displayed when a
tree node is selected.
SelectedImageKey
16 Gets or sets the key of the default image shown when a TreeNode is in a
selected state.
SelectedNode
17
Gets or sets the tree node that is currently selected in the tree view control.
ShowLines
18 Gets or sets a value indicating whether lines are drawn between tree nodes in
the tree view control.
ShowNodeToolTips
Gets or sets a value indicating ToolTips are shown when the mouse pointer
19
hovers over a TreeNode.
ShowPlusMinus
20 Gets or sets a value indicating whether plus-sign (+) and minus-sign (-)
buttons are displayed next to tree nodes that contain child tree nodes.
ShowRootLines
21 Gets or sets a value indicating whether lines are drawn between the tree
nodes that are at the root of the tree view.
Sorted
22 Gets or sets a value indicating whether the tree nodes in the tree view are
sorted.
StateImageList
23 Gets or sets the image list that is used to indicate the state of the TreeView
and its nodes.
Text
24
Gets or sets the text of the TreeView.
TopNode
25
Gets or sets the first fully-visible tree node in the tree view control.
TreeViewNodeSorter
26 Gets or sets the implementation of IComparer to perform a custom sort of
the TreeView nodes.
VisibleCount
27 Gets the number of tree nodes that can be fully visible in the tree view
control.
The following are some of the commonly used methods of the TreeView control −
CollapseAll
1
Collapses all the nodes including all child nodes in the tree view control.
ExpandAll
2
Expands all the nodes.
GetNodeAt
3
Gets the node at the specified location.
GetNodeCount
4
Gets the number of tree nodes.
Sort
5
Sorts all the items in the tree view control.
ToString
6
Returns a string containing the name of the control.
Example
TreeView1.Nodes(0).Nodes.Add("Hardware")
TreeView1.Nodes(0).Nodes(1).Nodes.Add("Printer")
TreeView1.Nodes(0).Nodes(1).Nodes.Add("keyboard")
TreeView1.Nodes(0).Nodes(1).Nodes(0).Nodes.Add("keyboard")
End Sub
End Class
Output