0% found this document useful (0 votes)
7 views

Unit 3 - Visual Programming Material

Uploaded by

maheskrishna5267
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

Unit 3 - Visual Programming Material

Uploaded by

maheskrishna5267
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 27

UNIT 3

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.

Properties of the ProgressBar Control

The following are some of the commonly used properties of the ProgressBar control –

Sr.No. Property & Description


Maximum
1
Gets or sets the maximum value of the range of the control
Minimum
2
Gets or sets the minimum value of the range of the control
Value
3
Gets or sets the current position of the progress bar
Example

Public Class Form2

Private Sub Form2_Load(sender As Object, e As EventArgs) Handles MyBase.Load

ProgressBar1.Minimum = 0
ProgressBar1.Maximum = 100
ProgressBar1.Value = 0

End Sub

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

If TextBox1.Text = "kjc" and TextBo x2.Text = "123" Then


ProgressBar1.Value = 100
MessageBox.Show("Username is authenticated")
Else
MessageBox.Show("Recheck your username and password")
End If

End Sub

Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click

Application.Exit()

End Sub

Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click

TextBox1.Text = "" TextBox2.Text = ""

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

Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick


ProgressBar1.Increment(10)
If ProgressBar1.Value = 100 Then
Timer1.Stop()
End If
End Sub
End Class

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.

Public Class Form1


Private Sub CheckBox1_CheckedChanged(sender As Object, e As EventArgs) Handles
CheckBox1.CheckedChanged
MessageBox.Show("you are select VB.NET")
End Sub

Private Sub CheckBox2_CheckedChanged(sender As Object, e As EventArgs) Handles


CheckBox2.CheckedChanged
MessageBox.Show("you are select JAVA")
End Sub
End Class

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.

Public Class Form1


Private Sub RadioButton1_CheckedChanged(sender As Object, e As EventArgs) Handles
RadioButton1.CheckedChanged
If (RadioButton1.Checked = True) Then
MessageBox.Show("You are Select VB.NET")
End If
End Sub

Private Sub RadioButton2_CheckedChanged(sender As Object, e As EventArgs) Handles


RadioButton2.CheckedChanged
If (RadioButton2.Checked = True) Then
MessageBox.Show("You are Select JAVA")
End If
End Sub
End Class

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 form in design view


RADIO BUTTON CONTROL
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.
Let's create three radio buttons by dragging RadioButton controls from the Toolbox and
dropping on the form

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.

Properties of the RadioButton Control

The following are some of the commonly used properties of the RadioButton control −

Sr.No. Property & Description

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.

Methods of the RadioButton Control

The following are some of the commonly used methods of the RadioButton control −

Sr.No. Method Name & Description

PerformClick
1
Generates a Click event for the control, simulating a click by a user.

Events of the RadioButton Control

The following are some of the commonly used events of the RadioButton control −

Sr.No Event & Description

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

Properties of the ListBox Control

The following are some of the commonly used properties of the ListBox control −

Sr.No. Property & Description


1 AllowSelection
Gets a value indicating whether the ListBox currently enables selection of list items.
2 BorderStyle
Gets or sets the type of border drawn around the list box.
3 ColumnWidth
Gets of sets the width of columns in a multicolumn list box.
4 HorizontalExtent
Gets or sets the horizontal scrolling area of a list box.
5 HorizontalScrollBar
Gets or sets the value indicating whether a horizontal scrollbar is displayed in the list
box.
6 ItemHeight
Gets or sets the height of an item in the list box.
7 Items
Gets the items of the list box.
8 MultiColumn
Gets or sets a value indicating whether the list box supports multiple columns.
9 ScrollAlwaysVisible
Gets or sets a value indicating whether the vertical scroll bar is shown at all times.
10 SelectedIndex
Gets or sets the zero-based index of the currently selected item in a list box.
11 SelectedIndices
Gets a collection that contains the zero-based indexes of all currently selected items in
the list box.
12 SelectedItem
Gets or sets the currently selected item in the list box.
13 SelectedItems
Gets a collection containing the currently selected items in the list box.
14 SelectedValue
Gets or sets the value of the member property specified by the ValueMember property.
15 SelectionMode
Gets or sets the method in which items are selected in the list box. This property has
values −
 None
 One
 MultiSimple
 MultiExtended
16 Text
Gets or searches for the text of the currently selected item in the list box.
17 TopIndex
Gets or sets the index of the first visible item of a list box.
Methods of the ListBox Control

The following are some of the commonly used methods of the ListBox control −

Sr.No. Method Name & Description


1 BeginUpdate
Prevents the control from drawing until the EndUpdate method is called, while items
are added to the ListBox one at a time.
2 ClearSelected
Unselects all items in the ListBox.
3 EndUpdate
Resumes drawing of a list box after it was turned off by the BeginUpdate method.
4 FindString
Finds the first item in the ListBox that starts with the string specified as an argument.
5 FindStringExact
Finds the first item in the ListBox that exactly matches the specified string.
6 GetSelected
Returns a value indicating whether the specified item is selected.
7 SetSelected
Selects or clears the selection for the specified item in a ListBox.
8 OnSelectedIndexChanged
Raises the SelectedIndexChanged event.

Events of the ListBox Control

The following are some of the commonly used events of the ListBox control −

Sr.No. Event & Description


1 Click
Occurs when a list box is selected.
2 SelectedIndexChanged
Occurs when the SelectedIndex property of a list box is changed.
Example

Public Class Form1

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

ListBox1.Items.Add(TextBox1.Text)

End Sub

Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e


As System.EventArgs) Handles ListBox1.SelectedIndexChanged

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.

Some Common Resizing Scenarios


Now that you have been told what docking, anchoring, and auto-scrolling are, here are a few
forms that demonstrate using the new layout features.
A Standard One-Large-Control Dialog Box

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.

S.No Group box control Panel control


A Group box control can be placed with
1 A panel control can’t be placed with a title.
a title.
The group box control cannot display
2 The panel control can display the scroll bar.
the scroll bar.
Border Style property is not supported To display Border we use Border Style
3
by Group Box Property.
It doesnot have click event. Other
It has MouseMove, MouseDown, MouseUp
4 events that are missing are
events.
MouseMove, MouseDown, MouseUp.

How to add Panel

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.

Properties of the PictureBox Control

The following are some of the commonly used properties of the PictureBox control −

Sr.No. Property & Description


1 AllowDrop
Specifies whether the picture box accepts data that a user drags on it.
2 ErrorImage
Gets or specifies an image to be displayed when an error occurs during the image-
loading process or if the image load is cancelled.
3 Image
Gets or sets the image that is displayed in the control.
4 ImageLocation
Gets or sets the path or the URL for the image displayed in the control.
5 InitialImage
Gets or sets the image displayed in the control when the main image is loaded.
6 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.
7 TabIndex
Gets or sets the tab index value.
8 TabStop
Specifies whether the user will be able to focus on the picture box by using the TAB
key.
9 Text
Gets or sets the text for the picture box.
10 WaitOnLoad
Specifies whether or not an image is loaded synchronously

Example

Public Class Form1

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)


Handles MyBase.Load
PictureBox1.Image = Image.FromFile("d:\testImage.jpg")
PictureBox1.SizeMode = PictureBoxSizeMode.StretchImage
End Sub

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.

Properties of the TreeView Control

The following are some of the commonly used properties of the TreeView control −

Sr.No. Property & Description

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.

Methods of the TreeView Control

The following are some of the commonly used methods of the TreeView control −

Sr.No. Method Name & Description

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

Public Class Form1

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click


TreeView1.Nodes.Add("Computers")
TreeView1.Nodes(0).Nodes.Add("software")
TreeView1.Nodes(0).Nodes(0).Nodes.Add("Java")
TreeView1.Nodes(0).Nodes(0).Nodes.Add("C++")
TreeView1.Nodes(0).Nodes(0).Nodes(0).Nodes.Add("C++")

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

Private Sub TreeView1_AfterSelect(sender As Object, e As TreeViewEventArgs) Handles


TreeView1.AfterSelect
TextBox1.Text = e.Node.Text
TextBox2.Text = e.Node.FullPath
End Sub

End Class
Output

You might also like