30
Visual Basic .NET Programming Working with Windows Forms and Controls * Property of STI Page 1 of 30 TOPIC TITLE: Working with Windows Forms and Controls Specific Objectives: At the end of the topic session, the students are expected to: Cognitive: 1. Identify the use of some windows controls used in VB.NET, such as Image List, Tree View, List View, Tool Strip, Status Strip, Menu Strip and Progress Bar. 2. Describe the different properties, methods and events that correspond to the mentioned controls. Affective: 1. Listen to others with respect. 2. Participate in class discussions actively. MATERIALS/EQUIPMENT: o topic slides o OHP TOPIC PREPARATION: o Have the students research or review on the following Windows controls: Image List Tree View List View Tool Strip Status Strip Menu Strip Progress Bar o It is imperative for the instructor to incorporate various kinds of teaching strategies while discussing the suggested topics. The instructor may use the suggested learning activities below to facilitate a thorough and creative discussion of the topic. o Prepare the slides to be presented in the class. TOPIC PRESENTATION: The topic will revolve around other Windows Controls. This will be the suggested flow of discussion for the course topic: 1. Introduce to the students the topics to be covered in this session. 2. For Session 14, discuss ImageList, TreeView, and ListView. Enumerate their corresponding properties, methods and events as well as provide the steps in creating them. Also, provide example for each control. 3. For Session 15, discuss ToolStrip, StatusStrip, MenuStrip, and ProgressBar by providing examples for each control..

MELJUN CORTES Vb.net handout working with windows forms and controls_part_ii

Embed Size (px)

Citation preview

Page 1: MELJUN CORTES Vb.net handout working with windows forms and controls_part_ii

Visual Basic .NET Programming

Working with Windows Forms and Controls * Property of STI Page 1 of 30

TOPIC TITLE: Working with Windows Forms and Controls Specific Objectives: At the end of the topic session, the students are expected to: Cognitive:

1. Identify the use of some windows controls used in VB.NET, such as Image List, Tree View, List View, Tool Strip, Status Strip, Menu Strip and Progress Bar.

2. Describe the different properties, methods and events that correspond to the mentioned controls.

Affective:

1. Listen to others with respect. 2. Participate in class discussions actively.

MATERIALS/EQUIPMENT:

o topic slides o OHP

TOPIC PREPARATION:

o Have the students research or review on the following Windows controls:

• Image List

• Tree View

• List View

• Tool Strip

• Status Strip

• Menu Strip

• Progress Bar

o It is imperative for the instructor to incorporate various kinds of teaching strategies while discussing the suggested topics. The instructor may use the suggested learning activities below to facilitate a thorough and creative discussion of the topic.

o Prepare the slides to be presented in the class.

TOPIC PRESENTATION: The topic will revolve around other Windows Controls. This will be the suggested flow of discussion for the course topic:

1. Introduce to the students the topics to be covered in this session.

2. For Session 14, discuss ImageList, TreeView, and ListView. Enumerate their corresponding properties, methods and events as well as provide the steps in creating them. Also, provide example for each control.

3. For Session 15, discuss ToolStrip, StatusStrip, MenuStrip, and ProgressBar by providing examples for each control..

Page 2: MELJUN CORTES Vb.net handout working with windows forms and controls_part_ii

Visual Basic .NET Programming

Working with Windows Forms and Controls * Property of STI Page 2 of 30

Windows Forms and Controls Page 1 of 74

Working with Windows Forms and Controls * Property of STIPage 1 of 74

Visual Basic .NET Programming

Windows Forms Windows Forms Windows Forms Windows Forms and Controlsand Controlsand Controlsand Controls

� Windows Controls

� Image List

� Tree View

� List View

� Tool Strip

� Status Strip

� Menu Strip

� Progress Bar

Windows Forms and Controls These are the topics to be discussed under the Windows Forms and Controls:

o Windows Controls � Image List � Tree View � List View � Tool Strip � Status Strip � Menu Strip � Progress Bar

[Windows Forms and Controls, Page 1 of 74]

ImageList Control Page 2 of 74

Working with Windows Forms and Controls * Property of STIPage 2 of 74

Visual Basic .NET Programming

ImageListImageListImageListImageListControlControlControlControl

� an invisible control that manages a

collection of images that are typically used

by other controls

� added in the program as a resource and

does not have any graphical presentation in the application

� represented in .NET by the

System.Windows.Forms.ImageList class

ImageList Control

ImageList control is an invisible control that manages a collection of images that are typically used by other controls such as ListView, TreeView or ToolStrip. An image list (like a main menu, context menu, toolbar or standard dialog box) is added in the program as a resource and does not have any graphical presentation in the application. In short, it is added as a component and is placed on the component tray at design time. It is represented in .NET by the System.Windows.Forms.ImageList class.

[ImageList Control, Page 2 of 74]

ImageList Properties Page 3 of 74

Working with Windows Forms and Controls * Property of STIPage 3 of 74

Visual Basic .NET Programming

ImageListImageListImageListImageListPropertiesPropertiesPropertiesProperties

Gets or sets the size of the

images in the image list.

Image Size

Gets the

ImageList.ImageCollection for

this

Images

Gets a value indicating whether

the underlying Win32 handle

has been created.

HandleCreated

Gets the handle of the image

list object.

Handle

Gets the color depth of the

image list.

ColorDepth

DescriptionName

ImageList Properties Listed below are some of the common ImageList properties.

Name Description

ColorDepth Gets the color depth of the image list.

Handle Gets the handle of the image list object.

HandleCreated Gets a value indicating whether the underlying Win32 handle has been created.

Images Gets the ImageList.ImageCollection for this.

Image Size Gets or sets the size of the images in the image list.

ImageStream Gets the handle to the ImageListStreamer associated with this image list.

Tag Gets or sets an object that contains additional data about the ImageList.

TransparentColor Gets or sets the color to treat as transparent.

[ImageList Properties, Pages 3-4 of 74]

Page 3: MELJUN CORTES Vb.net handout working with windows forms and controls_part_ii

Visual Basic .NET Programming

Working with Windows Forms and Controls * Property of STI Page 3 of 30

ImageList Properties Page 4 of 74

Working with Windows Forms and Controls * Property of STIPage 4 of 74

Visual Basic .NET Programming

ImageListImageListImageListImageListPropertiesPropertiesPropertiesProperties

DescriptionName

Gets or sets the color to treat

as transparent.

TransparentColor

Gets or sets an object that

contains additional data about

the ImageList.

Tag

Gets the handle to the

ImageListStreamer associated

with this image list.

ImageStream

ImageList Methods Pages 5 of 74

Working with Windows Forms and Controls * Property of STIPage 5 of 74

Visual Basic .NET Programming

ImageListImageListImageListImageListMethodsMethodsMethodsMethods

Retrieves the current

lifetime service object that

controls the lifetime policy

for this instance.

GetLifetimeService

Serves as a hash function for

a particular type.

GetHashCode

Determines whether two

Object instances are equal.

Equals

Draws the indicated image.Draw

Releases the resources used

by the Component.

Dispose

Creates an object that

contains all the relevant

information required to

generate a proxy used to

communicate with a remote

object.

CreateObjRef

DescriptionName

ImageList Methods Pages 6 of 74

Working with Windows Forms and Controls * Property of STIPage 6 of 74

Visual Basic .NET Programming

ImageListImageListImageListImageListMethodsMethodsMethodsMethods

DescriptionName

Returns a string that

represents the current

ImageList.

To String

Determines whether the

specified Object instances

are the same instance.

ReferenceEquals

Obtains a lifetime service

object to control the

lifetime policy for this

instance.

InitializeLifetimeSer

vice

Gets the Type of the current

instance.

GetType

ImageList Methods Listed below are some of the common ImageList methods.

Name Description

CreateObjRef Creates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object.

Dispose Releases the resources used by the Component.

Draw Draws the indicated image.

Equals Determines whether two Object instances are equal.

GetHashCode Serves as a hash function for a particular type.

GetLifetimeService Retrieves the current lifetime service object that controls the lifetime policy for this instance.

GetType Gets the Type of the current instance.

InitializeLifetimeService Obtains a lifetime service object to control the lifetime policy for this instance.

ReferenceEquals Determines whether the specified Object instances are the same instance.

To String Returns a string that represents the current ImageList.

[ImageList Methods, Pages 5-6 of 74]

Page 4: MELJUN CORTES Vb.net handout working with windows forms and controls_part_ii

Visual Basic .NET Programming

Working with Windows Forms and Controls * Property of STI Page 4 of 30

ImageList Even Page 7 of 74

Working with Windows Forms and Controls * Property of STIPage 7 of 74

Visual Basic .NET Programming

ImageListImageListImageListImageListEventsEventsEventsEvents

Occurs when the handle is created.

RecreateHandle

Adds an event handler to

listen to the Disposed event

on the component. (Inherited from Component.)

Disposed

DescriptionName

ImageList Events Listed below are some of the common ImageList events.

Name Description

Disposed

Adds an event handler to listen to the Disposed event on the component. (Inherited from Component.)

RecreateHandle Occurs when the handle is created.

[ImageList Event, Page 7 of 74]

Creating ImageList Pages 8 of 74

Working with Windows Forms and Controls * Property of STIPage 8 of 74

Visual Basic .NET Programming

Creating Creating Creating Creating ImageListImageListImageListImageList

� to add an ImageList to a program, drag

ImageList control from the toolbox

� to load images into new ImageList, select

Images from the Properties window and

click its corresponding ellipsis(…).

� to add new images to the image list, click the Add button

� to remove images, click on the image then

click the Remove button

Creating ImageList Pages 9 of 74

Working with Windows Forms and Controls * Property of STIPage 9 of 74

Visual Basic .NET Programming

Creating Creating Creating Creating ImageListImageListImageListImageList

� Example:

For intLoopIndex As Integer = 0 To

openFileDialog1.FileNames.Length

– 1

ImagesList1.Images.Add(Image.From

File(OpenDialog1.FileNames(intLoo

pIndex)))

Next intLoopIndex

Creating ImageList

1. To add an ImageList to a program, drag an ImageList control from the Toolbox to the form.

2. To load images into the new ImageList, select Images from the

Properties window and click its corresponding ellipsis. The Images Collection Editor appears.

3. To add new images to the ImageList, click the Add button (which also lets to browse to various image files)

4. To remove images, click on the image to be removed then click the Remove button.

The images in an image list are not sized automatically to match the images that are load into it. To set the image size, click the ImageSize property and enter the width and height, separated by comma. To load images into an image list at runtime, use the Images collection’s Add method.

Example:

For intLoopIndex As Integer = 0 To

openFileDialog1.FileNames.Length – 1

Page 5: MELJUN CORTES Vb.net handout working with windows forms and controls_part_ii

Visual Basic .NET Programming

Working with Windows Forms and Controls * Property of STI Page 5 of 30

ImagesList1.Images.Add(Image.FromFile(OpenDialo

g1.FileNames(intLoopIndex)))

Next intLoopIndex

The sample code given above lets the user select a number of images using a File Open Dialog box. [Creating ImageList, Pages 8-9 of 74]

Using ImageList Page 10 of 74

Working with Windows Forms and Controls * Property of STIPage 10 of 74

Visual Basic .NET Programming

Using Using Using Using ImageListImageListImageListImageList

� change the ImageList property of the

control to ImageList component in the

form

Using ImageList To use the ImageList in a control, select the ImageList component added on the form from the ImageList property of the control

In this example, the ImageList property of a Button is set to ImageList1.

[Using ImageList, Page 10 of 74]

TreeView Control TreeViews are used to display a hierarchy of nodes. Each node can have several child nodes. In the sample figure shown below, the left pane, which displays the folders, is a Tree View.

Page 6: MELJUN CORTES Vb.net handout working with windows forms and controls_part_ii

Visual Basic .NET Programming

Working with Windows Forms and Controls * Property of STI Page 6 of 30

TreeView Page 11 of 74

Working with Windows Forms and Controls * Property of STIPage 11 of 74

Visual Basic .NET Programming

TreeViewTreeViewTreeViewTreeViewControlControlControlControl

� used to display a hierarchy of nodes

� each node can have several child nodes

� applies a tree data structure

Example:

The TreeView control applies a tree data structure, which is the most appropriate structure for storing hierarchically structured data. As in the example above, each file in a computer belongs to a folder which may belong to a larger folder. Any given folder is the child of another folder or even the root folder. To expand or collapse parent nodes, click the plus (+) or minus (-) sign in the boxes in front of each node. When a parent node is expanded, its child nodes are visible. Images from an images list in each node can be displayed also, such as folders and documents. [TreeView Control, Page 11 of 74]

The TreeNode Editor Pages 12 of 74

Working with Windows Forms and Controls * Property of STIPage 12 of 74

Visual Basic .NET Programming

The The The The TreeNodeTreeNodeTreeNodeTreeNodeEditorEditorEditorEditor

� To add items to TreeView control:

� click the ellipsis button on the Nodesproperty to display the TreeNode editor

� use the Add Root button

� to add children to that node, select the

node and click the Add Child button

� Text to any node can be added in the Textbox in the Appearance section under Node

Properties

The TreeNode Editor To add items to TreeView control:

1. Click the ellipsis button on the Nodes property. TreeNode Editor appears.

2. Use the Add Root button to add a top-level node or a parent node.

3. Select the parent node where child nodes are to be added then click the Add Child button.

4. Text to any node can be added in the Text box in the Appearance section under Node Properties or the text next to any node can be double-clicked directly to edit it.

Page 7: MELJUN CORTES Vb.net handout working with windows forms and controls_part_ii

Visual Basic .NET Programming

Working with Windows Forms and Controls * Property of STI Page 7 of 30

The TreeNode Editor Pages 13 of 74

Working with Windows Forms and Controls * Property of STIPage 13 of 74

Visual Basic .NET Programming

The The The The TreeNodeTreeNodeTreeNodeTreeNodeEditorEditorEditorEditor

� To remove items from the TreeView

control:

� click the ellipsis button on the Nodesproperty to display the TreeNode editor

� click the node to be deleted from the

TreeView then click the Remove

button

To remove items from the TreeView control:

1. Click the ellipsis button on the TreeView’s Nodes property. The TreeNode Editor window appears.

2. Click the node, either parent or child node, to be deleted from

the TreeView and click the Remove button. [The TreeNode Editor, Pages 12-13 of 74]

TreeView Properties Page 14 of 74

Working with Windows Forms and Controls * Property of STIPage 14 of 74

Visual Basic .NET Programming

TreeViewTreeViewTreeViewTreeViewPropertiesPropertiesPropertiesProperties

Gets or sets the border

style of the tree view

control.

BorderStyle

Infrastructure. Gets or

sets the layout of the

background image for

the TreeView control.

(Overrides

Control..::.BackgroundI

mageLayout.)

BackgroundImageLayout

Infrastructure. Gets or

set the background

image for the TreeView

control. (Overrides

Control..::.BackgroundI

mage.)

BackgroundImage

DescriptionName

TreeView Properties Page 15 of 74

Working with Windows Forms and Controls * Property of STIPage 15 of 74

Visual Basic .NET Programming

TreeViewTreeViewTreeViewTreeViewPropertiesPropertiesPropertiesProperties

Gets or sets a value indicating

whether a tree node label takes

on the appearance of a hyperlink

as the mouse pointer passes over

it.

HotTracking

Gets or sets a value indicating

whether the selected tree node

remains highlighted even when

the tree view has lost the focus.

HideSelection

DescriptionName

Gets or sets a value indicating

whether the selection highlight

spans the width of the tree view

control.

FullRowSelect

Gets or sets the mode in which

the control is drawn.

DrawMode

Gets or sets a value indicating

whether check boxes are

displayed next to the tree nodes

in the tree view control.

CheckBoxes

TreeView Properties Listed below are some of the common TreeView properties.

Name Description

BackgroundImage Infrastructure. Gets or set the background image for the TreeView control. (Overrides Control..::.BackgroundImage.)

BackgroundImageLayout

Infrastructure. Gets or sets the layout of the background image for the TreeView control. (Overrides Control..::.BackgroundImageLayout.)

BorderStyle Gets or sets the border style of the tree view control.

CheckBoxes Gets or sets a value indicating whether check boxes are displayed next to the tree nodes in the tree view control.

DrawMode Gets or sets the mode in which the control is drawn.

FullRowSelect Gets or sets a value indicating whether the selection highlight spans the width of the tree view control.

HideSelection Gets or sets a value indicating whether the selected tree node remains highlighted even when the tree view has lost the focus.

HotTracking Gets or sets a value indicating whether a tree node label takes on the appearance of a hyperlink as the mouse pointer passes over it.

ImageIndex Gets or sets the image-list index value of the default image that is displayed by the tree nodes.

ImageKey Gets or sets the key of the default image for each node in the TreeView control when it is in an unselected state.

ImageList Gets or sets the ImageList that contains the Image objects used by the tree nodes.

Indent Gets or sets the distance to indent each of the child tree node levels.

ItemHeight Gets or sets the height of each tree node in the tree view control.

Page 8: MELJUN CORTES Vb.net handout working with windows forms and controls_part_ii

Visual Basic .NET Programming

Working with Windows Forms and Controls * Property of STI Page 8 of 30

TreeView Properties Page 16 of 74

Working with Windows Forms and Controls * Property of STIPage 16 of 74

Visual Basic .NET Programming

TreeViewTreeViewTreeViewTreeViewPropertiesPropertiesPropertiesProperties

Gets or sets the image-list index

value of the default image that is

displayed by the tree nodes.

ImageIndex

DescriptionName

Gets or sets the color of the lines

connecting the nodes of the

TreeView control.

LineColor

Gets or sets a value indicating

whether the label text of the tree

nodes can be edited.

LabelEdit

Gets or sets the height of each tree

node in the tree view control.

ItemHeight

Gets or sets the distance to indent

each of the child tree node levels.

Indent

Gets or sets the ImageList that

contains the Image objects used by

the tree nodes.

ImageList

Gets or sets the key of the default

image for each node in the TreeView

control when it is in an unselected

state.

ImageKey

TreeView Properties Page 17 of 74

Working with Windows Forms and Controls * Property of STIPage 17 of 74

Visual Basic .NET Programming

TreeViewTreeViewTreeViewTreeViewPropertiesPropertiesPropertiesProperties

DescriptionName

Gets or sets the image list

index value of the image

that is displayed when a tree

node is selected.

SelectedImageIndex

Gets or sets a value

indicating whether the tree

view control displays scroll

bars when they are needed.

Scrollable

Gets or sets the delimiter

string that the tree node

path uses.

PathSeparator

Infrastructure. Gets or sets

the spacing between the

TreeView control's contents

and its edges.

Padding

Gets the collection of tree

nodes that are assigned to

the tree view control.

Nodes

TreeView Properties Page 18 of 74

Working with Windows Forms and Controls * Property of STIPage 18 of 74

Visual Basic .NET Programming

TreeViewTreeViewTreeViewTreeViewPropertiesPropertiesPropertiesProperties

DescriptionName

Gets or sets a value indicating

whether plus-sign (+) and

minus-sign (-) buttons are

displayed next to tree nodes

that contain child tree nodes.

ShowPlusMinus

Gets or sets a value indicating

ToolTips are shown when the

mouse pointer hovers over a

TreeNode.

ShowNodeToolTips

Gets or sets a value indicating

whether lines are drawn

between tree nodes in the

tree view control.

ShowLines

Gets or sets the tree node

that is currently selected in

the tree view control.

SelectedNode

Gets or sets the key of the

default image shown when a

TreeNode is in a selected

state.

SelectedImageKey

LabelEdit Gets or sets a value indicating whether the label text of the tree nodes can be edited.

LineColor Gets or sets the color of the lines connecting the nodes of the TreeView control.

Nodes Gets the collection of tree nodes that are assigned to the tree view control.

Padding Infrastructure. Gets or sets the spacing between the TreeView control's contents and its edges.

PathSeparator Gets or sets the delimiter string that the tree node path uses.

Scrollable Gets or sets a value indicating whether the tree view control displays scroll bars when they are needed.

SelectedImageIndex Gets or sets the image list index value of the image that is displayed when a tree node is selected.

SelectedImageKey Gets or sets the key of the default image shown when a TreeNode is in a selected state.

SelectedNode Gets or sets the tree node that is currently selected in the tree view control.

ShowLines 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 hovers over a TreeNode.

ShowPlusMinus 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 Gets or sets a value indicating whether lines are drawn between the tree nodes that are at the root of the tree view.

Sorted Gets or sets a value indicating whether the tree nodes in the tree view are sorted.

StateImageList Gets or sets the image list used for indicating the state of the TreeView and its nodes.

TopNode Gets or sets the first fully-visible tree node in the tree view control.

VisibleCount Gets the number of tree nodes that can be fully visible in the tree view control.

[TreeView Properties, Pages 14-19 of 74]

Page 9: MELJUN CORTES Vb.net handout working with windows forms and controls_part_ii

Visual Basic .NET Programming

Working with Windows Forms and Controls * Property of STI Page 9 of 30

TreeView Properties Page 19 of 74

Working with Windows Forms and Controls * Property of STIPage 19 of 74

Visual Basic .NET Programming

TreeViewTreeViewTreeViewTreeViewPropertiesPropertiesPropertiesProperties

DescriptionName

Gets the number of tree nodes

that can be fully visible in the

tree view control.

VisibleCount

Gets or sets the first fully-visible

tree node in the tree view

control.

TopNode

Gets or sets the image list used

for indicating the state of the

TreeView and its nodes.

StateImageList

Gets or sets a value indicating

whether the tree nodes in the

tree view are sorted.

Sorted

Gets or sets a value indicating

whether lines are drawn between

the tree nodes that are at the

root of the tree view.

ShowRootLines

TreeView Methods Page 20 of 74

Working with Windows Forms and Controls * Property of STIPage 20 of 74

Visual Basic .NET Programming

TreeViewTreeViewTreeViewTreeViewMethodsMethodsMethodsMethods

Sorts the items in TreeView

control.

Sort

Retrieves the number of

tree nodes assigned to the

tree view control.

GetNodeCount

Overloaded. Retrieves the

tree node that is at the

specified.

GetNodeAt

Returns an

OwnerDrawPropertyBag for

the specified TreeNode.

GetItemRenderStyles

Expands all the tree nodes.ExpandAll

Enables the redrawing of

the tree view.

EndUpdate

Collapses all the tree nodes.CollapseAll

Disables any redrawing of

the tree view.

BeginUpdate

DescriptionName

TreeView Methods Listed below are some of the common TreeView methods.

Name Description

BeginUpdate Disables any redrawing of the tree view.

CollapseAll Collapses all the tree nodes.

EndUpdate Enables the redrawing of the tree view.

ExpandAll Expands all the tree nodes.

GetItemRenderStyles location.Infrastructure. Returns an OwnerDrawPropertyBag for the specified TreeNode.

GetNodeAt Overloaded. Retrieves the tree node that is at the specified

GetNodeCount Retrieves the number of tree nodes, optionally including those in all subtrees, assigned to the tree view control.

Sort Sorts the items in TreeView control.

[TreeView Methods, Page 20 of 74]

TreeView Events Page 21 of 74

Working with Windows Forms and Controls * Property of STIPage 21 of 74

Visual Basic .NET Programming

TreeViewTreeViewTreeViewTreeViewEventsEventsEventsEvents

Occurs before the tree node label text is edited.

BeforeLabelEdit

Occurs before the tree node is expanded.

BeforeExpand

Occurs before the tree node is collapsed.

BeforeCollapse

Occurs before the tree node check box is checked.

BeforeCheck

Occurs after the tree node is selected.

AfterSelect

Occurs after the tree node label text is edited.

AfterLabelEdit

Occurs after the tree node is expanded.

AfterExpand

Occurs after the tree node is collapsed.

AfterCollapse

Occurs after the tree node check box is checked.

AfterCheck

DescriptionName

TreeView Events Listed below are some of the common TreeView events.

Name Description

AfterCheck Occurs after the tree node check box is checked.

AfterCollapse Occurs after the tree node is collapsed.

AfterExpand Occurs after the tree node is expanded.

AfterLabelEdit Occurs after the tree node label text is edited.

AfterSelect Occurs after the tree node is selected.

BeforeCheck Occurs before the tree node check box is checked.

BeforeCollapse Occurs before the tree node is collapsed.

BeforeExpand Occurs before the tree node is expanded.

BeforeLabelEdit Occurs before the tree node label text is edited.

BeforeSelect Occurs before the tree node is selected.

Page 10: MELJUN CORTES Vb.net handout working with windows forms and controls_part_ii

Visual Basic .NET Programming

Working with Windows Forms and Controls * Property of STI Page 10 of 30

Tree View Events Page 22 of 74

Working with Windows Forms and Controls * Property of STIPage 22 of 74

Visual Basic .NET Programming

TreeViewTreeViewTreeViewTreeViewEventsEventsEventsEvents

DescriptionName

Occurs when the TreeView is drawn.

Paint

Occurs when the mouse hovers over a TreeNode.

NodeMouseDoub

leClick

Occurs when the user clicks a TreeNode with the mouse.

NodeMouseClick

Occurs when the user begins dragging a node.

ItemDrag

Occurs when a TreeView is

drawn and the DrawMode

property is set to a

TreeViewDrawMode value other than Normal.

DrawNode

Occurs before the tree node is selected.

BeforeSelect

DrawNode Occurs when a TreeView is drawn and the DrawMode property is set to a TreeViewDrawMode value other than Normal.

ItemDrag Occurs when the user begins dragging a node.

NodeMouseClick Occurs when the user clicks a TreeNode with the mouse.

NodeMouseDoubleClick

Occurs when the mouse hovers over a TreeNode.

Paint Occurs when the TreeView is drawn.

[TreeView Events, Pages 21-22 of 74]

Adding nodes at runtime Page 23 of 74

Working with Windows Forms and Controls * Property of STIPage 23 of 74

Visual Basic .NET Programming

Adding nodes Adding nodes Adding nodes Adding nodes at runtimeat runtimeat runtimeat runtime

Private Sub MyForm_Load(ByVal sender As

System.Object, ByVal e As

System.EventArgs) Handles MyBase.Load

treeView1.Nodes.Clear()

treeView1.Nodes.Add("Programming

Languages")

Dim node1 As New TreeNode(“Structured

Programming Languages")

node1.Nodes.Add("C")

node1.Nodes.Add("COBOL")

Dim node2 As New TreeNode("Object Oriented

Programming")

Dim subnode1 As TreeNode =

node2.Nodes.Add(“Traditional Object

Oriented Languages")

Dim subnode2 As TreeNode =

node2.Nodes.Add(“Framework and Runtime

Based Object Oriented Languages")

subnode1.Nodes.Add(“C++")

subnode2.Nodes.Add(“Java")

subnode2.Nodes.Add("C#")

subnode2.Nodes.Add(“Visual Basic")

treeView1.Nodes(0).Nodes.Add(node1)

treeView1.Nodes(0).Nodes.Add(node2)

End Sub

Adding nodes at runtime The following code adds a sample tree hierarchy on the form's Load event. Private Sub MyForm_Load(ByVal sender As

System.Object, ByVal e As System.EventArgs) Handles

MyBase.Load

treeView1.Nodes.Clear()

treeView1.Nodes.Add("Programming Languages")

Dim node1 As New TreeNode(“Structured Programming

Languages")

node1.Nodes.Add("C")

node1.Nodes.Add("COBOL")

Dim node2 As New TreeNode("Object Oriented

Programming")

Dim subnode1 As TreeNode =

node2.Nodes.Add(“Traditional Object Oriented

Languages")

Dim subnode2 As TreeNode =

node2.Nodes.Add(“Framework and Runtime Based

Object Oriented Languages")

subnode1.Nodes.Add(“C++")

subnode2.Nodes.Add(“Java")

subnode2.Nodes.Add("C#")

subnode2.Nodes.Add(“Visual Basic")

treeView1.Nodes(0).Nodes.Add(node1)

treeView1.Nodes(0).Nodes.Add(node2)

End Sub

Page 11: MELJUN CORTES Vb.net handout working with windows forms and controls_part_ii

Visual Basic .NET Programming

Working with Windows Forms and Controls * Property of STI Page 11 of 30

Adding nodes at runtime Page 24 of 74

Working with Windows Forms and Controls * Property of STIPage 24 of 74

Visual Basic .NET Programming

Adding nodes Adding nodes Adding nodes Adding nodes at runtimeat runtimeat runtimeat runtime

The sample code provided on the previous page produces the following:

[Adding nodes at runtime, Pages 23-24 of 74]

ListView Control Page 25 of 74

Working with Windows Forms and Controls * Property of STIPage 25 of 74

Visual Basic .NET Programming

ListViewControl

� used to list the items in the right side of

the windows

� serves as complimentary to the TreeView

� shows what files resides in a particular

directory

ListView Control ListView is used to list the items in the right side of the window and it serves as complimentary to the TreeView. It shows what files resides in a particular directory. In the figure below, ListView is displayed on the right pane of the Form1 window. Example:

[ListView Control, Page 25 of 74]

ListView Properties Listed below are some of the common ListView properties.

Name Description

Activation The property that holds the type of action the user must take to activate an item.

Alignment Aligns the items in the control.

AllowColumnReorder Indicator if the user can drag column headers to reorder columns in the control.

Page 12: MELJUN CORTES Vb.net handout working with windows forms and controls_part_ii

Visual Basic .NET Programming

Working with Windows Forms and Controls * Property of STI Page 12 of 30

ListView Properties Page 26 of 74

Working with Windows Forms and Controls * Property of STIPage 26 of 74

Visual Basic .NET Programming

ListViewListViewListViewListViewPropertiesPropertiesPropertiesProperties

Collection containing all items in the control.

Items

Determines the currently checked items in the control.

CheckedItems

Determines the currently checked items in the control.

CheckedIndices

Indicates when a check box

appears next to each item in the control.

CheckBoxes

When set to true, icons are automatically kept arranged.

AutoArrange

Indicator if the user can drag

column headers to reorder columns in the control.

AllowColumnRe

order

Aligns the items in the control.Alignment

The property that holds the type

of action the user must take to activate an item.

Activation

DescriptionName

ListView Properties Page 27 of 74

Working with Windows Forms and Controls * Property of STIPage 27 of 74

Visual Basic .NET Programming

ListViewListViewListViewListViewPropertiesPropertiesPropertiesProperties

DescriptionName

Contains the items that are selected in the control.

SelectedItems

Contains the indexes of the selected items in the control.

SelectedIndices

This is used to add a scroll bar

to the control when there is not

enough room to display all items.

Scrollable

The property that holds the

space between the ListViewcontrol and its contents.

Padding

When set to true, the user can

edit the labels of items in the control.

LabelEdit

AutoArrange When set to true, icons are automatically kept arranged.

CheckBoxes Indicates when a check box appears next to each item in the control.

CheckedIndices Determines the currently checked items in the control.

CheckedItems Determines the currently checked items in the control.

Items Collection containing all items in the control.

LabelEdit When set to true, the user can edit the labels of items in the control.

Padding The property that holds the space between the ListView control and its contents.

Scrollable This is used to add a scroll bar to the control when there is not enough room to display all items.

SelectedIndices Contains the indexes of the selected items in the control.

SelectedItems Contains the items that are selected in the control.

ListView Properties, Pages 26-27 of 74]

ListView Methods Page 28 of 74

Working with Windows Forms and Controls * Property of STIPage 28 of 74

Visual Basic .NET Programming

ListViewListViewListViewListViewMethodsMethodsMethodsMethods

Finds the next item from a

given point, searching in the specified direction.

FindNearestItem

Finds the first ListViewItem

with that begins with the given text value.

FindItemWithText

Ensures that the specified

item is visible within the

control, scrolling the contents of the control if necessary.

EnsureVisible

Removes all items and columns from the control.

Clear

Resizes the width of the given

column as indicated by the resize style.

AutoResizeColumn

Arranges items in the control

when they are displayed as icons.

ArrangeIcons

DescriptionName

ListView Methods Listed below are some of the common ListView methods.

Name Description

ArrangeIcons Arranges items in the control when they are displayed as icons.

AutoResizeColumn Resizes the width of the given column as indicated by the resize style.

Clear Removes all items and columns from the control.

EnsureVisible Ensures that the specified item is visible within the control, scrolling the contents of the control if necessary.

FindItemWithText Finds the first ListViewItem with that begins with the given text value.

FindNearestItem Finds the next item from a given point, searching in the specified direction.

GetItemAt Retrieves the item at the specified location.

Page 13: MELJUN CORTES Vb.net handout working with windows forms and controls_part_ii

Visual Basic .NET Programming

Working with Windows Forms and Controls * Property of STI Page 13 of 30

ListView Methods Page 29 of 74

Working with Windows Forms and Controls * Property of STIPage 29 of 74

Visual Basic .NET Programming

ListViewListViewListViewListViewMethodsMethodsMethodsMethods

DescriptionName

Sorts the items of the list view.Sort

Forces a range of

ListViewItem objects to be redrawn.

RedrawItems

Conceals the control from the user.

Hide

Retrieves the bounding

rectangle for an item within the control.

GetItemRect

Retrieves the item at the specified location.

GetItemAt

GetItemRect Retrieves the bounding rectangle for an item within the control.

Hide Conceals the control from the user.

RedrawItems Forces a range of ListViewItem objects to be redrawn.

Sort Sorts the items of the list view.

[ListView Methods, Pages 28-29of 74]

ListView Events Page 30 of 74

Working with Windows Forms and Controls * Property of STIPage 30 of 74

Visual Basic .NET Programming

ListViewEvents

Occurs after the width of a

column is successfully changed.

ColumnWidthChanged

Occurs when the column header order is changed.

ColumnReordered

Occurs when the user

clicks a column header within the list view control.

ColumnClick

Occurs when the contents

of the display area for a

ListView in virtual mode

have changed, and the

ListView determines that a

new range of items is needed.

CacheVirtualItems

Occurs when the user

starts editing the label of an item.

BeforeLabelEdit

Occurs when the label for

an item is edited by the user.

AfterLabelEdit

DescriptionName

ListView Events Page 31 of 74

Working with Windows Forms and Controls * Property of STIPage 31 of 74

Visual Basic .NET Programming

ListViewEvents

DescriptionName

Occurs when an item is activated.

ItemActivate

Occurs when the details

view of a ListView is

drawn and the OwnerDrawproperty is set to true.

DrawSubItem

Occurs when the details

view of a ListView is

drawn and the OwnerDrawproperty is set to true.

DrawSubItem

Occurs when a ListView is

drawn and the OwnerDrawproperty is set to true.

DrawItem

Occurs when the details

view of a ListView is

drawn and the OwnerDrawproperty is set to true.

DrawColumnHeader

Occurs when the width of a column is changing.

ColumnWidthChanging

ListView Events Listed below are some of the common ListView events.

Name Description

AfterLabelEdit Occurs when the label for an item is edited by the user.

BeforeLabelEdit Occurs when the user starts editing the label of an item.

CacheVirtualItems Occurs when the contents of the display area for a ListView in virtual mode have changed, and the ListView determines that a new range of items is needed.

ColumnClick Occurs when the user clicks a column header within the list view control.

ColumnReordered Occurs when the column header order is changed.

ColumnWidthChanged Occurs after the width of a column is successfully changed.

ColumnWidthChanging Occurs when the width of a column is changing.

DrawColumnHeader Occurs when the details view of a ListView is drawn and the OwnerDraw property is set to true.

DrawItem Occurs when a ListView is drawn and the OwnerDraw property is set to true.

DrawSubItem Occurs when the details view of a ListView is drawn and the OwnerDraw property is set to true.

DrawSubItem Occurs when the details view of a ListView is drawn and the OwnerDraw property is set to true.

ItemActivate Occurs when an item is activated.

ItemCheck Occurs when the check state of an item changes.

ItemChecked Occurs when the checked state of an item changes.

Page 14: MELJUN CORTES Vb.net handout working with windows forms and controls_part_ii

Visual Basic .NET Programming

Working with Windows Forms and Controls * Property of STI Page 14 of 30

ListView Events Page 32 of 74

Working with Windows Forms and Controls * Property of STIPage 32 of 74

Visual Basic .NET Programming

ListViewEvents

DescriptionName

Occurs when the value of

the RightToLeftLayoutproperty changes.

RightToLeftLayoutCha

nged

Occurs when the ListView

is in virtual mode and requires a ListViewItem.

RetrieveVirtualItem

Occurs when the selection state of an item changes.

ItemSelectionChanged

Occurs when the mouse hovers over an item.

ItemMouseHover

Occurs when the user begins dragging an item.

ItemDrag

Occurs when the checked state of an item changes.

ItemChecked

Occurs when the check state of an item changes.

ItemCheck

ListView Events Page 33 of 74

Working with Windows Forms and Controls * Property of STIPage 33 of 74

Visual Basic .NET Programming

ListViewEvents

DescriptionName

Occurs when a ListView is

in virtual mode and the

selection state of a range of items has changed.

VirtualItemsSelection

RangeChanged

Occurs when the index of

the selected item in the list view control changes.

SelectedIndexChanged

Occurs when the ListView

is in virtual mode and a search is taking place.

SearchForVirtualItem

ItemDrag Occurs when the user begins dragging an item.

ItemMouseHover Occurs when the mouse hovers over an item.

ItemSelectionChanged Occurs when the selection state of an item changes.

RetrieveVirtualItem Occurs when the ListView is in virtual mode and requires a ListViewItem.

RightToLeftLayoutChanged Occurs when the value of the RightToLeftLayout property changes.

SearchForVirtualItem Occurs when the ListView is in virtual mode and a search is taking place.

SelectedIndexChanged Occurs when the index of the selected item in the list view control changes.

VirtualItemsSelectionRangeChanged

Occurs when a ListView is in virtual mode and the selection state of a range of items has changed.

[ListView Events, Pages 30-33 of 74]

Creating ListViews Page 34 of 74

Working with Windows Forms and Controls * Property of STIPage 34 of 74

Visual Basic .NET Programming

Creating Creating Creating Creating ListViewsListViewsListViewsListViews

� add a ListView control to the Form

� click the ListView’s Items property ellipsis

(…) to open the ListViewItem Collection Editor

� click the Add button to add a ListViewItem.

� type a caption to the corresponding Textproperty of the ListViewItem

Creating ListViews To create a list view:

1. Drag the ListView control from the toolbox to the Form. 2. Click the corresponding ellipsis (…) of the ListView’s Items

property to open the ListViewItem Collection Editor. 3. Click the Add button to add a ListViewItem. 4. Type a caption to the corresponding Text property of the

ListViewItem.

Page 15: MELJUN CORTES Vb.net handout working with windows forms and controls_part_ii

Visual Basic .NET Programming

Working with Windows Forms and Controls * Property of STI Page 15 of 30

Creating ListViews Page 35 of 74

Working with Windows Forms and Controls * Property of STIPage 35 of 74

Visual Basic .NET Programming

Creating Creating Creating Creating ListViewsListViewsListViewsListViews

� 5 Views

� View.LargeIcon

� View.SmallIcon

Here is an example of a ListViewItem Editor:

There are five different views that can be presented by the ListView. These views are similar to the views that appear in Windows Explorer.

• View.LargeIcon – displays large icons (32 x 32 pixels)

• View.SmallIcon – displays small icons (16 x 16 pixels)

• View.List – displays small icons. Items are arranged in

columns, but with no column header.

Page 16: MELJUN CORTES Vb.net handout working with windows forms and controls_part_ii

Visual Basic .NET Programming

Working with Windows Forms and Controls * Property of STI Page 16 of 30

Creating ListViews Page 36 of 74

Working with Windows Forms and Controls * Property of STIPage 36 of 74

Visual Basic .NET Programming

Creating Creating Creating Creating ListViewsListViewsListViewsListViews

� 5 Views (con’t)

� View.List

� View.Details

Creating ListViews Page 37 of 74

Working with Windows Forms and Controls * Property of STIPage 37 of 74

Visual Basic .NET Programming

Creating Creating Creating Creating ListViewsListViewsListViewsListViews

� 5 Views (con’t)

� View.Tiles

• View.Details – report view (also called details mode)

displays items in multiple columns, displaying column header and fields.

• View.Tiles – displays large icons (32 x 32 pixels) with

several labels.

[Creating ListViews, Pages 34-37 of 74]

Adding/Removing items on ListView Page 38 of 74

Working with Windows Forms and Controls * Property of STIPage 38 of 74

Visual Basic .NET Programming

Adding/Removing Adding/Removing Adding/Removing Adding/Removing items on items on items on items on ListViewListViewListViewListView

� to add items at runtime, use the Add

method of the Items property

� ListView1.Items.Add("List item

text",3)

� to remove items at runtime, use the RemoveAt or Clear method of the

Items property

� To remove the first item from the list:

• ListView1.Items.RemoveAt(0)

� To remove all the items from the list:

• ListView1.Items.Clear()

Adding/Removing items on ListView

To add items at runtime, use the Add method of the Items property.

ListView1.Items.Add("List item text",3)

The code above adds a new item with image index 3. To remove items at runtime, use the RemoveAt or Clear method of the

Items property.

• To remove the first item from the list: ListView1.Items.RemoveAt(0)

• To remove all the items from the list: ListView1.Items.Clear()

[Adding/Removing items on ListView, Page 38 of 74]

Page 17: MELJUN CORTES Vb.net handout working with windows forms and controls_part_ii

Visual Basic .NET Programming

Working with Windows Forms and Controls * Property of STI Page 17 of 30

Manipulating ListView in Code Page 39 of 74

Working with Windows Forms and Controls * Property of STIPage 39 of 74

Visual Basic .NET Programming

Manipulating Manipulating Manipulating Manipulating ListViewListViewListViewListView in Codein Codein Codein Code

� create a ListView

� Dim ListView1 As New ListView()

� set the view to show details

� ListView1.View = View.Details

� allow user to edit item text

� ListView1.LabelEdit = True

� display check boxes

� ListView1.CheckBoxes = True

� sort the items in the list in ascending order

� ListView1.Sorting =

SortOrder.Ascending

Manipulating ListView in Code Some of the codes in manipulating ListView control:

• Create a ListView Dim ListView1 As New ListView()

• Set the view to show details ListView1.View = View.Details

• Allow the user to edit item text ListView1.LabelEdit = True

• Display check boxes ListView1.CheckBoxes = True

• Sort the items in the list in ascending order ListView1.Sorting = SortOrder.Ascending

[Manipulating ListView in Code, Page 39 of 74]

SelectedIndexChanged Event Page 40 of 74

Working with Windows Forms and Controls * Property of STIPage 40 of 74

Visual Basic .NET Programming

SelectedIndexChangedSelectedIndexChangedSelectedIndexChangedSelectedIndexChangedEventEventEventEvent

� SelectedIndexChanged event

� triggered when the index of the selected

item in the list view control changes

� Example:

Private Sub

ListView1_SelectedIndexChanged(By

Val sender As System.Object,

ByVal e As System.EventArgs)

Handles

ListView1.SelectedIndexChanged

Dim item As ListViewItem

For Each item In

ListView1.SelectedItems

MessageBox.Show(item.Text)

Next

End Sub

SelectedIndexChanged Event Page 41 of 74

Working with Windows Forms and Controls * Property of STIPage 41 of 74

Visual Basic .NET Programming

SelectedIndexChangedSelectedIndexChangedSelectedIndexChangedSelectedIndexChangedEventEventEventEvent

� Example: (con’t)

� Sample screens

SelectedIndexChanged Event SelectedIndexChanged event is the most commonly used event for

ListView. It is triggered when the index of the selected item in the list view control changes.

Example:

Private Sub ListView1_SelectedIndexChanged(ByVal

sender As System.Object, ByVal e As

System.EventArgs) Handles

ListView1.SelectedIndexChanged

Dim item As ListViewItem

For Each item In ListView1.SelectedItems

MessageBox.Show(item.Text)

Next

End Sub

The code above displays a message box with the text value of the selected item in the ListView. [SelectedIndexChanged Event, Pages 40-41 of 74]

Page 18: MELJUN CORTES Vb.net handout working with windows forms and controls_part_ii

Visual Basic .NET Programming

Working with Windows Forms and Controls * Property of STI Page 18 of 30

ToolStrip Control Page 42 of 74

Working with Windows Forms and Controls * Property of STIPage 42 of 74

Visual Basic .NET Programming

ToolStripToolStripToolStripToolStripControlControlControlControl

� ToolStripItem

� element similar to Windows context menu

� ToolStrip provides toolbars and other user

interface elements that support many

appearance options

ToolStrip Control Page 43 of 74

Working with Windows Forms and Controls * Property of STIPage 43 of 74

Visual Basic .NET Programming

ToolStripToolStripToolStripToolStripControlControlControlControl

� provides a container for windows toolbar

objects such as:

� ToolStripButton

� ToolStripComboBox

� ToolStripSplitButton

� ToolStripLabel

� ToolStripSeparator

� ToolStripDropDownButton

� ToolStripProgressBar

� ToolStripTextBox

ToolStrip Control Page 44 of 74

Working with Windows Forms and Controls * Property of STIPage 44 of 74

Visual Basic .NET Programming

ToolStripToolStripToolStripToolStripControlControlControlControl

� Example:

Private Sub InitializeComponent()

toolStripContainer1 = New

System.Windows.Forms.ToolStripCon

tainer()

toolStrip1 = New

System.Windows.Forms.ToolStrip()

'Add items to the ToolStrip.

toolStrip1.Items.Add("One")

toolStrip1.Items.Add("Two")

toolStrip1.Items.Add("Three")

'Add the ToolStrip to the top

panel of the ToolStripContainer.

toolStripContainer1.TopToolStripP

anel.Controls.Add(toolStrip1)

'Add the ToolStripContainer

to the form.

Controls.Add(toolStripContainer1)

End Sub 'InitializeComponent

ToolStrip Control A ToolStripItem is an element that is similar to Windows context menu which can be button, combo box, text box, or label that can be contained in a ToolStrip control or a ToolStripDropDown control. ToolStrip provides toolbars and other user interface elements that support many appearance options.

ToolStrip provides a container for windows toolbar objects such as:

• ToolStripButton – a toolbar button that supports images and text.

• ToolStripComboBox – a textbox where user can enter text along with a list from which the user can select text to fill the textbox.

• ToolStripSplitButton – a combination of a regular button and a drop-down button.

• ToolStripLabel – used in a Status Bar or ToolStrip as a comment or title.

• ToolStripSeparator – used to visually group elements.

• ToolStripDropDownButton – a button that supports drop-down functionality.

• ToolStripProgressBar – a Windows Progress Bar control contained in a StatusStrip.

• ToolStripTextBox – used to enter text. The example code given below creates a ToolStrip control. Private Sub InitializeComponent()

toolStripContainer1 = New

System.Windows.Forms.ToolStripContainer()

toolStrip1 = New

System.Windows.Forms.ToolStrip()

' Add items to the ToolStrip.

toolStrip1.Items.Add("One")

toolStrip1.Items.Add("Two")

toolStrip1.Items.Add("Three")

' Add the ToolStrip to the top panel of the

ToolStripContainer.

toolStripContainer1.TopToolStripPanel.Controls.Add(to

olStrip1)

' Add the ToolStripContainer to the form.

Controls.Add(toolStripContainer1)

End Sub 'InitializeComponent

[ToolStrip Control, Pages 42-44 of 74]

Page 19: MELJUN CORTES Vb.net handout working with windows forms and controls_part_ii

Visual Basic .NET Programming

Working with Windows Forms and Controls * Property of STI Page 19 of 30

ToolStrip Properties Page 45 of 74

Working with Windows Forms and Controls * Property of STIPage 45 of 74

Visual Basic .NET Programming

ToolStripToolStripToolStripToolStripPropertiesPropertiesPropertiesProperties

It defines a value indicating how

the ToolStrip lays out the items collection.

LayoutStyle

It is used to retrieve all the items that belong to a ToolStrip.

Items

It defines the space around the ToolStrip move handle.

GripMargin

It defines which ToolStrip borders

are docked to its parent control

and determines how a ToolStrip is resized with its parent.

Dock

It defines the cursor that is

displayed when the mouse pointer is over the ToolStrip.

Cursor

It defines the edges of the

container to which a ToolStrip is

bound and determines how a ToolStrip is resized with its parent.

Anchor

DescriptionName

ToolStrip Properties Page 46 of 74

Working with Windows Forms and Controls * Property of STIPage 46 of 74

Visual Basic .NET Programming

ToolStripToolStripToolStripToolStripPropertiesPropertiesPropertiesProperties

DescriptionName

It defines the direction in

which to draw text on a ToolStrip.

TextDirection

It defines a value indicating

whether the ToolStrip

stretches from end to end in the ToolStripContainer.

Stretch

It defines a value indicating

whether ToolTips are to be

displayed on ToolStripitems.

ShowItemToolTips

It defines the painting styles

to be applied to the ToolStrip.

RenderMode

ToolStrip Properties Listed below are some of the common ToolStrip properties.

Name Description

Anchor It defines the edges of the container to which a ToolStrip is bound and determines how a ToolStrip is resized with its parent.

Cursor It defines the cursor that is displayed when the mouse pointer is over the ToolStrip.

Dock It defines which ToolStrip borders are docked to its parent control and determines how a ToolStrip is resized with its parent.

GripMargin It defines the space around the ToolStrip move handle.

Items It is used to retrieve all the items that belong to a ToolStrip.

LayoutStyle It defines a value indicating how the ToolStrip lays out the items collection.

RenderMode It defines the painting styles to be applied to the ToolStrip.

ShowItemToolTips It defines a value indicating whether ToolTips are to be displayed on ToolStrip items.

Stretch It defines a value indicating whether the ToolStrip stretches from end to end in the ToolStripContainer.

TextDirection It defines the direction in which to draw text on a ToolStrip.

[ToolStrip Properties, Pages 45-46 of 74]

ToolStrip Methods Page 47 of 74

Working with Windows Forms and Controls * Property of STIPage 47 of 74

Visual Basic .NET Programming

ToolStripToolStripToolStripToolStripMethodsMethodsMethodsMethods

It is used to retrieved the next

ToolStripItem from the

specified reference point and

moving in the specified direction.

GetNextItem

It determines the item located at the specified location.

GetItemAt

It is used to retrieve the child control at a specified location.

GetChildAtPoint

DescriptionName

ToolStrip Methods Listed below are some of the common ToolStrip methods.

Name Description

GetChildAtPoint It is used to retrieve the child control at a specified location.

GetItemAt It determines the item located at the specified location.

GetNextItem It is used to retrieved the next ToolStripItem from the specified reference point and moving in the specified direction.

[ToolStrip Methods, Page 47 of 74]

Page 20: MELJUN CORTES Vb.net handout working with windows forms and controls_part_ii

Visual Basic .NET Programming

Working with Windows Forms and Controls * Property of STI Page 20 of 30

ToolStrip Events Page 48 of 74

Working with Windows Forms and Controls * Property of STIPage 48 of 74

Visual Basic .NET Programming

ToolStripToolStripToolStripToolStripEventsEventsEventsEvents

Triggers when the ToolStripItem is clicked.

ItemClicked

Triggers when a new

ToolStripItem is added to the ToolStripItemCollection.

ItemAdded

Occurs when the user stops dragging the ToolStrip control.

EndDrag

Triggers when the value of the Cursor property changes.

CursorChanged

Triggers when the user begins

to drag drop the ToolStripcontrol.

BeginDrag

Triggers when the AutoSizeproperty has changed.

AutoSizeChanged

DescriptionName

ToolStrip Events Page 49 of 74

Working with Windows Forms and Controls * Property of STIPage 49 of 74

Visual Basic .NET Programming

ToolStripToolStripToolStripToolStripEventsEventsEventsEvents

DescriptionName

Triggers when the ToolStripmove handle is painted.

PaintGrip

Triggers when the value of

the LayoutStyle property changes.

LayoutStyleChanged

Triggers when the layout of the ToolStrip is complete.

LayoutCompleted

Triggers when a

ToolStripItem is removed

from the ToolStripItemCollection.

ItemRemoved

ToolStrip Events Listed below are some of the common ToolStrip events.

Name Description

AutoSizeChanged Triggers when the AutoSize property has changed.

BeginDrag Triggers when the user begins to drag drop the ToolStrip control.

CursorChanged Triggers when the value of the Cursor property changes,

EndDrag Occurs when the user stops dragging the ToolStrip control.

ItemAdded Triggers when a new ToolStripItem is added to the ToolStripItemCollection.

ItemClicked Triggers when the ToolStripItem is clicked.

ItemRemoved Triggers when a ToolStripItem is removed from the ToolStripItemCollection.

LayoutCompleted Triggers when the layout of the ToolStrip is complete.

LayoutStyleChanged Triggers when the value of the LayoutStyle property changes.

PaintGrip Triggers when the ToolStrip move handle is painted.

[ToolStrip Events, Pages 48-49 of 74]

StatusStrip Control Page 50 of 74

Working with Windows Forms and Controls * Property of STIPage 50 of 74

Visual Basic .NET Programming

StatusStripStatusStripStatusStripStatusStripControlControlControlControl

� replaces previous Windows Forms

StatusBar control

� appears at the bottom of a window and

gives the user some additional information

StatusStrip Control StatusStrip control replaces previous Windows Forms StatusBar control. It is more powerful control than StatusBar as it provides many built-in features such as progress bar, status bar, dropdown button, and splitter. StatusStrip appears at the bottom of a window and gives the user some additional information.

Page 21: MELJUN CORTES Vb.net handout working with windows forms and controls_part_ii

Visual Basic .NET Programming

Working with Windows Forms and Controls * Property of STI Page 21 of 30

StatusStrip Control Page 51 of 74

Working with Windows Forms and Controls * Property of STIPage 51 of 74

Visual Basic .NET Programming

StatusStripStatusStripStatusStripStatusStripControlControlControlControl

� Example:

Private Sub InitializeComponent()

statusStrip1 = New System.Windows.Forms.StatusStrip()

toolStripStatusLabel1 = New System.Windows.Forms.ToolStripStatusLabel()

statusStrip1.SuspendLayout()

SuspendLayout()

'The following code sample demonstrates the syntax for setting various StatusStrip properties.

statusStrip1.Dock = System.Windows.Forms.DockStyle.Top

statusStrip1.GripStyle = System.Windows.Forms.ToolStripGripStyle.Visible

statusStrip1.Items.AddRange(New System.Windows.Forms.ToolStripItem() {toolStripStatusLabel1})

StatusStrip Control Page 52 of 74

Working with Windows Forms and Controls * Property of STIPage 52 of 74

Visual Basic .NET Programming

StatusStripStatusStripStatusStripStatusStripControlControlControlControl

� Example: (con’t)

statusStrip1.LayoutStyle = System.Windows.Forms.ToolStripLayoutStyle.HorizontalStackWithOverflow

statusStrip1.Location = New System.Drawing.Point(0, 0)

statusStrip1.Name = "statusStrip1"

statusStrip1.ShowItemToolTips = True

statusStrip1.Size = New System.Drawing.Size(292, 22)

statusStrip1.SizingGrip = False

statusStrip1.Stretch = False

statusStrip1.TabIndex = 0

statusStrip1.Text = "statusStrip1"

StatusStrip Control Page 53 of 74

Working with Windows Forms and Controls * Property of STIPage 53 of 74

Visual Basic .NET Programming

StatusStripStatusStripStatusStripStatusStripControlControlControlControl

� Example: (con’t)

' toolStripStatusLabel1

toolStripStatusLabel1.Name = "toolStripStatusLabel1"

toolStripStatusLabel1.Size = New System.Drawing.Size(109, 17)

toolStripStatusLabel1.Text = "toolStripStatusLabel1"

' Form1

ClientSize = New System.Drawing.Size(292, 273)

Controls.Add(statusStrip1)

Name = "Form1"

statusStrip1.ResumeLayout(False)

statusStrip1.PerformLayout()

ResumeLayout(False)

PerformLayout()

End Sub

The figure above shows an example of StatusStrip control. The code below creates a StatusStrip control.

Private Sub InitializeComponent()

statusStrip1 = New

System.Windows.Forms.StatusStrip()

toolStripStatusLabel1 = New

System.Windows.Forms.ToolStripStatusLabel()

statusStrip1.SuspendLayout()

SuspendLayout()

'

' The following code example demonstrates

the syntax for setting various StatusStrip

properties.

statusStrip1.Dock =

System.Windows.Forms.DockStyle.Top

statusStrip1.GripStyle =

System.Windows.Forms.ToolStripGripStyle.Visible

statusStrip1.Items.AddRange(New

System.Windows.Forms.ToolStripItem()

{toolStripStatusLabel1})

statusStrip1.LayoutStyle =

System.Windows.Forms.ToolStripLayoutStyle.Horiz

ontalStackWithOverflow

statusStrip1.Location = New

System.Drawing.Point(0, 0)

statusStrip1.Name = "statusStrip1"

statusStrip1.ShowItemToolTips = True

statusStrip1.Size = New

System.Drawing.Size(292, 22)

statusStrip1.SizingGrip = False

statusStrip1.Stretch = False

statusStrip1.TabIndex = 0

statusStrip1.Text = "statusStrip1"

'

' toolStripStatusLabel1

'

toolStripStatusLabel1.Name =

"toolStripStatusLabel1"

toolStripStatusLabel1.Size = New

System.Drawing.Size(109, 17)

toolStripStatusLabel1.Text =

Page 22: MELJUN CORTES Vb.net handout working with windows forms and controls_part_ii

Visual Basic .NET Programming

Working with Windows Forms and Controls * Property of STI Page 22 of 30

"toolStripStatusLabel1"

'

' Form1

'

ClientSize = New System.Drawing.Size(292,

273)

Controls.Add(statusStrip1)

Name = "Form1"

statusStrip1.ResumeLayout(False)

statusStrip1.PerformLayout()

ResumeLayout(False)

PerformLayout()

End Sub

[StatusStrip Control, Pages 50-53 of 74]

StatusStrip Properties Page 54 of 74

Working with Windows Forms and Controls * Property of STIPage 54 of 74

Visual Basic .NET Programming

StatusStripStatusStripStatusStripStatusStripPropertiesPropertiesPropertiesProperties

It defines a value indicating

whether ToolTips are shown for the StatusStrip.

ShowItemToolTips

It defines a value indicating

how the StatusStrip lays out the items collection.

LayoutStyle

It defines the visibility of the

grip used to reposition the control.

GripStyle

It defines which StatusStrip

borders are docked to its

parent control and determines

how a StatusStrip is resized with its parent.

Dock

DescriptionName

StatusStrip Properties Page 55 of 74

Working with Windows Forms and Controls * Property of STIPage 55 of 74

Visual Basic .NET Programming

StatusStripStatusStripStatusStripStatusStripPropertiesPropertiesPropertiesProperties

DescriptionName

It defines a value indicating

whether the StatusStrip

stretches from end to end in its container.

Stretch

It defines a value indicating

whether a sizing handle (grip)

is displayed in the lower-right corner of the control.

SizingGrip

It determines the boundaries

of the sizing handle (grip) for a StatusStrip.

SizeGripBounds

StatusStrip Properties Listed below are some of the common StatusStrip properties.

Name Description

Dock It defines which StatusStrip borders are docked to its parent control and determines how a StatusStrip is resized with its parent.

GripStyle It defines the visibility of the grip used to reposition the control.

LayoutStyle It defines a value indicating how the StatusStrip lays out the items collection.

ShowItemToolTips It defines a value indicating whether ToolTips are shown for the StatusStrip.

SizeGripBounds It determines the boundaries of the sizing handle (grip) for a StatusStrip.

SizingGrip It defines a value indicating whether a sizing handle (grip) is displayed in the lower-right corner of the control.

Stretch It defines a value indicating whether the StatusStrip stretches from end to end in its container.

[StatusStrip Properties, Pages 54-55 of 74]

Page 23: MELJUN CORTES Vb.net handout working with windows forms and controls_part_ii

Visual Basic .NET Programming

Working with Windows Forms and Controls * Property of STI Page 23 of 30

StatusStrip Methods Page 56 of 74

Working with Windows Forms and Controls * Property of STIPage 56 of 74

Visual Basic .NET Programming

StatusStripStatusStripStatusStripStatusStripMethodsMethodsMethodsMethods

It is used to determine

whether a character is an

input character that the item recognizes.

IsInputChar

It is used to retrieve the

next ToolStripItem from

the specified reference

point and moving in the specified direction.

GetNextItem

It defines the visual

arrangement for the ToolStrip.

CreateLayoutSettings

It is used to create a

default

ToolStripStatusLabel with

the specified text, image

and event handler on a new StatusStrip instance.

CreateDefaultItem

It is used to create a new

accessibility object for the control.

CreateAccessibility_

Instance

DescriptionName

StatusStrip Methods Page 57 of 74

Working with Windows Forms and Controls * Property of STIPage 57 of 74

Visual Basic .NET Programming

StatusStripStatusStripStatusStripStatusStripMethodsMethodsMethodsMethods

DescriptionName

It is used to retrieve a value

that sets the ToolStripItem to the specified visibility state.

SetVisibleCore

It is used to anchor a

ToolStripItem to a particular place on a ToolStrip.

SetItemLocation

It is used to reset the

collection of displayed and

overflow items after a layout is done.

SetDisplayedItems

it is used to set the specified bounds of this control.

SetBoundsCore

It is used to control the return location of the focus.

RestoreFocus

It is used to determine

whether the specified key is a

regular input key or a special

key that requires preprocessing.

IsInputKey

StatusStrip Methods Listed below are some of the common StatusStrip methods.

Name Description

CreateAccessibilityInstance

It is used to create a new accessibility object for the control.

CreateDefaultItem It is used to create a default ToolStripStatusLabel with the specified text, image and event handler on a new StatusStrip instance.

CreateLayoutSettings It defines the visual arrangement for the ToolStrip.

GetNextItem It is used to retrieve the next ToolStripItem from the specified reference point and moving in the specified direction.

IsInputChar It is used to determine whether a character is an input character that the item recognizes.

IsInputKey It is used to determine whether the specified key is a regular input key or a special key that requires preprocessing.

RestoreFocus It is used to control the return location of the focus.

SetBoundsCore it is used to set the specified bounds of this control.

SetDisplayedItems It is used to reset the collection of displayed and overflow items after a layout is done.

SetItemLocation It is used to anchor a ToolStripItem to a particular place on a ToolStrip.

SetVisibleCore It is used to retrieve a value that sets the ToolStripItem to the specified visibility state.

[StatusStrip Methods, Pages 56-57 of 74]

StatusStrip Events Page 58 of 74

Working with Windows Forms and Controls * Property of STIPage 58 of 74

Visual Basic .NET Programming

StatusStripStatusStripStatusStripStatusStripEventsEventsEventsEvents

Triggers when the value of the Renderer property changes.

RendererChanged

Triggers when the ToolStripmove handle is painted.

PaintGrip

Triggers when a ToolStripItem

is removed from the ToolStripItemCollection.

ItemRemoved

Triggers when the ToolStripItem is clicked.

ItemClicked

Triggers when a new

ToolStripItem is added to the ToolStripItemCollection.

ItemAdded

The event handler used to to

listen to the Disposed event on the component.

Disposed

Triggers when the AutoSizeproperty has changed.

AutoSizeChanged

DescriptionName

StatusStrip Events Listed below are some of the common StatusStrip events.

Name Description

AutoSizeChanged Triggers when the AutoSize property has changed.

Disposed The event handler used to to listen to the Disposed event on the component.

ItemAdded Triggers when a new ToolStripItem is added to the ToolStripItemCollection. (Inherited from ToolStrip.)

ItemClicked Triggers when the ToolStripItem is clicked. (Inherited from ToolStrip.)

ItemRemoved Triggers when a ToolStripItem is removed from the ToolStripItemCollection. (Inherited from ToolStrip.)

PaintGrip Triggers when the ToolStrip move handle is painted. (Inherited from ToolStrip.)

Page 24: MELJUN CORTES Vb.net handout working with windows forms and controls_part_ii

Visual Basic .NET Programming

Working with Windows Forms and Controls * Property of STI Page 24 of 30

RendererChanged Triggers when the value of the Renderer property changes.

[StatusStrip Events, Page 58 of 74]

MenuStrip Control Page 59 of 74

Working with Windows Forms and Controls * Property of STIPage 59 of 74

Visual Basic .NET Programming

MenuStripMenuStripMenuStripMenuStripControlControlControlControl

� displays application commands and options group by functionality

� supports MDI and menu merging, tool tips,

and overflow

MenuStrip Control Page 60 of 74

Working with Windows Forms and Controls * Property of STIPage 60 of 74

Visual Basic .NET Programming

MenuStripMenuStripMenuStripMenuStripControl Control Control Control

� Creating an MDI Window list on a MenuStrip

� create a Form and set its IsMdiContainer

property to True

� add a MenuStrip to the Form

� add two top-level menu items to the

MenuStrip

• to add a menu item, select MenuItem from the drop-down menu

� set the Text property of the menu items

� add a submenu item, to &File and name it

as OpenSubmenu then set its Text

property to &Open

• to add a submenu item, select MenuItemfrom the drop-down menu below the top-

level menu items

� click on the MenuStrip then set its

MdiWindowListItem property to WindowMenuItem

MenuStrip Control Page 61 of 74

Working with Windows Forms and Controls * Property of STIPage 61 of 74

Visual Basic .NET Programming

MenuStripMenuStripMenuStripMenuStripControlControlControlControl

� Creating an MDI Window list on a

MenuStrip (con’t)

� add another Form to the project and add a

control to it, such as another MenuStrip.

� double-click the OpenSubmenu menu item

� insert the following code to create and

display new instances of Form2 as MDI

children of Form1.

Private Sub

openToolStripMenuItem_Click(ByVal

sender As System.Object, ByVal e

As System.EventArgs)_ Handles

openToolStripMenuItem.Click

Dim NewMDIChild As New Form2()

'Set the parent form of the child

window.

NewMDIChild.MdiParent = Me

'Display the new form.

NewMDIChild.Show()End Sub

MenuStrip Control MenuStrip displays application commands and options group by functionality. It supports the multiple-document interface (MDI) and menu merging, tool tips, and overflow.

Creating an MDI Window list on a Menu Strip

1. Create a Form and set its IsMdiContainer property to True. 2. Add a MenuStrip to the Form. 3. Add two top-level menu items to the MenuStrip. Name them as

FileMenuItem and WindowMenuItem, respectively.

NOTE: To add a menu item, place the mouse pointer over the MenuStrip (with ‘Type Here’ text), click the appearing down arrow and then select MenuItem.

4. Set the Text property of FileMnuItem to &File and WindowMenuItem to &Window.

5. Add a submenu item, to &File and name it as OpenSubmenu then set its Text property to &Open.

NOTE: To add a submenu item, place the mouse pointer over the MenuStrip below the top-level menu items and then select MenuItem from the drop-down menu.

6. Click on the empty part of the MenuStrip. Set its MdiWindowListItem property to WindowMenuItem.

7. Add another Form to the project and add a control to it, such as another MenuStrip.

8. Double-click the OpenSubmenu menu item to show the code window where an event handler for the OpenSubmenu’s Click event can be created.

9. Within the event handler, insert the code provided on the next page.

Page 25: MELJUN CORTES Vb.net handout working with windows forms and controls_part_ii

Visual Basic .NET Programming

Working with Windows Forms and Controls * Property of STI Page 25 of 30

MenuStrip Control Page 62 of 74

Working with Windows Forms and Controls * Property of STIPage 62 of 74

Visual Basic .NET Programming

MenuStripMenuStripMenuStripMenuStripControlControlControlControl

� Creating an MDI Window list on a

MenuStrip (con’t)

� Sample screens

Private Sub openToolStripMenuItem_Click(ByVal

sender As System.Object, ByVal e As

System.EventArgs) Handles

openToolStripMenuItem.Click

Dim NewMDIChild As New Form2()

'Set the parent form of the child window.

NewMDIChild.MdiParent = Me

'Display the new form.

NewMDIChild.Show()

End Sub

The code above creates and displays new instances of Form2 as MDI children of Form1.

[MenuStrip Control, Pages 61-62 of 74] MenuStrip Properties Page 63 of 74

Working with Windows Forms and Controls * Property of STIPage 63 of 74

Visual Basic .NET Programming

MenuStripMenuStripMenuStripMenuStripPropertiesPropertiesPropertiesProperties

It sets or retrieves the

ToolStripMenuItem that is

used to display a list of

Multiple-document interface (MDI) child forms.

MdiWindowListItem

It retrieve all the items that belong to a ToolStrip.

Items

It defines image list that

contains the image displayed on a ToolStrip item.

ImageList

It identifies the visibility of

the grip used to reposition the control.

GripStyle

It determines the edges of

the container to which a

ToolStrip is bound and

determines how a ToolStripis resized with its parent.

Anchor

DescriptionName

MenuStrip Properties Listed below are some of the common MenuStrip properties.

Name Description

Anchor It determines the edges of the container to which a ToolStrip is bound and determines how a ToolStrip is resized with its parent. (Inherited from ToolStrip.)

GripStyle It identifies the visibility of the grip used to reposition the control.

ImageList It defines image list that contains the image displayed on a ToolStrip item. (Inherited from ToolStrip.)

Items It retrieve all the items that belong to a ToolStrip. (Inherited from ToolStrip.)

MdiWindowListItem It sets or retrieves the ToolStripMenuItem that is used to display a list of Multiple-document interface (MDI) child forms.

Name It identifies name of the control. (Inherited from Control.)

Orientation It diefines the orientation of the ToolStripPanel. (Inherited from ToolStrip.)

ShowItemToolTips It determines a value indicating whether ToolTips are shown for the MenuStrip.

ShortcutKeys It determines the shortcut keys associated with

Page 26: MELJUN CORTES Vb.net handout working with windows forms and controls_part_ii

Visual Basic .NET Programming

Working with Windows Forms and Controls * Property of STI Page 26 of 30

MenuStrip Properties Page 64 of 74

Working with Windows Forms and Controls * Property of STIPage 64 of 74

Visual Basic .NET Programming

MenuStripMenuStripMenuStripMenuStripPropertiesPropertiesPropertiesProperties

DescriptionName

It determines the shortcut

keys associated with the ToolStripMenuItem.

ShortcutKeys

It determines a value

indicating whether ToolTips are shown for the MenuStrip.

ShowItemToolTips

It diefines the orientation of the ToolStripPanel.

Orientation

It identifies name of the control.

Name

the ToolStripMenuItem.

[MenuStrip Properties, Pages 63-64 of 74]

MenuStrip Methods Page 65 of 74

Working with Windows Forms and Controls * Property of STIPage 65 of 74

Visual Basic .NET Programming

MenuStripMenuStripMenuStripMenuStripMethodsMethodsMethodsMethods

Method used to identify

whether a character is an

input character that the item recognizes.

IsInputChar

Method used to retrieve

the next MenuStripItem

from the specified

reference point and moving in the specified direction.

GetNextItem

This method provides the

visual arrangement for the MenuStrip.

CreateLayoutSettings

Method that creates a

MenuStripMenuItem with

the specified text, image, and event.

CreateDefaultItem

DescriptionName

MenuStrip Methods Page 66 of 74

Working with Windows Forms and Controls * Property of STIPage 66 of 74

Visual Basic .NET Programming

MenuStripMenuStripMenuStripMenuStripMethodsMethodsMethodsMethods

DescriptionName

Method used to retrieve a

value that sets the

MenuStripItem to the specified visibility state.

SetVisibleCore

Method used to anchor a

MenuStripItem to a

particular place on a MenuStrip.

SetItemLocation

Resets the collection of

displayed and overflow items after a layout is done.

SetDisplayedItems

Method used to identify

whether the specified key

is a regular input key or a

special key that requires preprocessing.

IsInputKey

MenuStrip Methods

Listed below are some of the common MenuStrip methods.

Name Description

CreateDefaultItem Method that creates a MenuStripMenuItem with the specified text, image, and event.

CreateLayoutSettings This method provides the visual arrangement for the MenuStrip.

GetNextItem Method used to retrieve the next MenuStripItem from the specified reference point and moving in the specified direction.

IsInputChar Method used to identify whether a character is an input character that the item recognizes.

IsInputKey Method used to identify whether the specified key is a regular input key or a special key that requires preprocessing.

SetDisplayedItems Resets the collection of displayed and overflow items after a layout is done.

SetItemLocation Method used to anchor a MenuStripItem to a particular place on a MenuStrip.

SetVisibleCore Method used to retrieve a value that sets the MenuStripItem to the specified visibility state.

[MenuStrip Methods, Pages 65-66 of 74]

Page 27: MELJUN CORTES Vb.net handout working with windows forms and controls_part_ii

Visual Basic .NET Programming

Working with Windows Forms and Controls * Property of STI Page 27 of 30

MenuStrip Events Page 67 of 74

Working with Windows Forms and Controls * Property of STIPage 67 of 74

Visual Basic .NET Programming

MenuStripMenuStripMenuStripMenuStripEventsEventsEventsEvents

Triggers when the MenuStrip is deactivated.

MenuDeactivate

Triggers when the user accesses

the menu with the keyboard or mouse.

MenuActivate

Triggers when a ToolStripItem is

removed from the ToolStripItemCollection.

ItemRemoved

Triggers when the ToolStripItemis clicked.

ItemClicked

Triggers when a new

ToolStripItem is added to the ToolStripItemCollection.

ItemAdded

DescriptionName

MenuStrip Events Listed below are some of the common MenuStrip events.

Name Description

ItemAdded Triggers when a new ToolStripItem is added to the ToolStripItemCollection. (Inherited from ToolStrip.)

ItemClicked Triggers when the ToolStripItem is clicked. (Inherited from ToolStrip.)

ItemRemoved Triggers when a ToolStripItem is removed from the ToolStripItemCollection. (Inherited from ToolStrip.)

MenuActivate Triggers when the user accesses the menu with the keyboard or mouse.

MenuDeactivate Triggers when the MenuStrip is deactivated.

[MenuStrip Events, Page 67 of 74]

ProgressBar Control Page 68 of 74

Working with Windows Forms and Controls * Property of STIPage 68 of 74

Visual Basic .NET Programming

ProgressBarProgressBarProgressBarProgressBarControlControlControlControl

� displays a bar that fills to indicate to the

user the progress of an operation

� gives the user some visual feedback on

how the operation is progressing

ProgressBar Control Page 69 of 74

Working with Windows Forms and Controls * Property of STIPage 69 of 74

Visual Basic .NET Programming

ProgressBarProgressBarProgressBarProgressBarControlControlControlControl

� Example:

Private Sub Button1_Click(ByVal

sender As System.Object, ByVal e

As System.EventArgs) Handles

Button1.Click

Timer1.Enabled = True

End Sub

Private Sub Timer1_Tick(ByVal

sender As System.Object, ByVal e

As System.EventArgs) Handles

Timer1.Tick

If ProgressBar1.Value <=

ProgressBar1.Maximum -1 Then

ProgressBar1.Value += 1

Else

Timer1.Enabled = False

End If

End Sub

ProgressBar Control Progress Bar displays a bar that fills to indicate to the user the progress of an operation. The idea is to give the user some visual feedback on how the operation is progressing and how long it will take for the operation to finish.

Example: Add a ProgressBar control from the toolbox to a form then set its Minimum property to 1, Maximum to 100, and Value to 1. Add a Button to the form and enter the following line of code to the button’s Click event handler. Timer1.Enabled = True

Add a Timer to the form and enter the following codes to the control’s Tick event handler. If ProgressBar1.Value <= ProgressBar1.Maximum -1 Then

ProgressBar1.Value += 1

Page 28: MELJUN CORTES Vb.net handout working with windows forms and controls_part_ii

Visual Basic .NET Programming

Working with Windows Forms and Controls * Property of STI Page 28 of 30

ProgressBar Control Page 70 of 74

Working with Windows Forms and Controls * Property of STIPage 70 of 74

Visual Basic .NET Programming

ProgressBarProgressBarProgressBarProgressBarControlControlControlControl

� Example: (con’t)

� Sample screens

Else

Timer1.Enabled = False

End If

In the sample code above, clicking the button starts a timer that steadily increments the Value property of the progress bar.

[ProgressBar Control, Pages 68-70 of 74]

ProgressBar Properties Page 71 of 74

Working with Windows Forms and Controls * Property of STIPage 71 of 74

Visual Basic .NET Programming

ProgressBarProgressBarProgressBarProgressBarPropertiesPropertiesPropertiesProperties

It is used to determine

thespace between the edges

of a ProgressBar control and its contents.

Padding

It provides the minimum

value of the range of the control.

Minimum

It provides the maximum

value of the range of the control.

Maximum

It is used to modify the font of text in the ProgressBar.

Font

It controls the layout of the

background image of the progress bar.

BackgroundImageLa

yout

It controls the background

image for the ProgressBarcontrol.

BackgroundImage

DescriptionName

ProgressBar Properties Page 72 of 74

Working with Windows Forms and Controls * Property of STIPage 72 of 74

Visual Basic .NET Programming

ProgressBarProgressBarProgressBarProgressBarPropertiesPropertiesPropertiesProperties

DescriptionName

It controls the current position of the progress bar.

Value

It provides the style o be used in the Progress bar.

Style

It provides the value that

will increase the current position of the progress bar.

Step

It indicates whether the

ProgressBar and any text it

contains are displayed from right to left.

RightToLeftLayout

ProgressBar Properties

Listed below are some of the common ProgressBar properties.

Name Description

BackgroundImage Property that controls the background image for the ProgressBar control.

BackgroundImageLayout

Property that controls the layout of the background image of the progress bar.

Font Used to modify the font of text in the ProgressBar.

Maximum Provides the maximum value of the range of the control.

Minimum Provides the minimum value of the range of the control.

Padding Used to determine the space between the edges of a ProgressBar control and its contents.

RightToLeftLayout Property that indicates whether the ProgressBar and any text it contains are displayed from right to left.

Step Provides the value that will increase the current position of the progress bar

Style Provides the style o be used in the Progress bar.

Value Property that controls the current position of the progress bar.

[ProgressBar Properties, Pages 71-72 of 74]

Page 29: MELJUN CORTES Vb.net handout working with windows forms and controls_part_ii

Visual Basic .NET Programming

Working with Windows Forms and Controls * Property of STI Page 29 of 30

ProgressBar Methods Page 73 of 74

Working with Windows Forms and Controls * Property of STIPage 73 of 74

Visual Basic .NET Programming

ProgressBarProgressBarProgressBarProgressBarMethodsMethodsMethodsMethods

It triggers the RightToLeftLayoutevent.

OnRightToLeftLayout_Changed

It triggers the HandleDestroyed event.

OnHandleDestroyed

It triggers the ForeColorChanged event.

OnForeColorChanged

It triggers the BackColorChanged event.

OnBackColorChanged

It is used to change the

current position of the progress bar by the specified amount.

Increment

DescriptionName

ProgressBar Methods Page 74 of 74

Working with Windows Forms and Controls * Property of STI

Page 74 of 74

Visual Basic .NET Programming

ProgressBarProgressBarProgressBarProgressBarMethodsMethodsMethodsMethods

DescriptionName

It returns a string that

represents the ProgressBarcontrol.

ToString

It resets the ForeColor to its default value.

ResetForeColor

It is used to change the

current position of the

progress bar by the

amount of the Step property.

PerformStep

ProgressBar Methods Listed below are some of the common ProgressBar methods.

Name Description

Increment It is used to change the current position of the progress bar by the specified amount.

OnBackColorChanged Triggers the BackColorChanged event.

OnForeColorChanged Triggers the ForeColorChanged event.

OnHandleDestroyed Triggers the HandleDestroyed event.

OnRightToLeftLayoutChanged

Triggers the RightToLeftLayoutevent.

PerformStep It is used to change the current position of the progress bar by the amount of the Step property.

ResetForeColor It resets the ForeColor to its default value.

ToString It returns a string that represents the ProgressBar control.

[ProgressBar Methods , Pages 73-74 of 74]

EVALUATION/GENERALIZATION:

• Other important controls in VB.NET are ImageList, TreeView, ListView, ToolStrip, StatusStrip, MenuStrip, ProgressBar.

• ImageList control stores a collection of images that are frequently used by other controls, such as TreeView and ListView, at runtime.

• TreeView and ListView controls can be used together. For instance, the Windows Explorer window that is composed of Tree View on the left pane and List View on the right.

• ToolStrip control provides toolbars and other user interface elements that support many appearance options.

• StatusStrip control appears at the bottom of a window and gives the user some additional information.

• MenuStrip control displays application commands and options group by functionality.

• ProgressBar control displays a bar that fills to indicate to the user the progress of an operation.

Page 30: MELJUN CORTES Vb.net handout working with windows forms and controls_part_ii

Visual Basic .NET Programming

Working with Windows Forms and Controls * Property of STI Page 30 of 30

REFERENCES:

� Microsoft Official Course, (2002), 2373B: Programming with Microsoft Visual Basic .NET, Microsoft Corporation

� Holzner, Steven, (2003), Sams teach yourself Microsoft Visual Basic.Net 2003 in 21 days, USA, Sams Publishing

� Hurwitz, Dan, (2003), Programming .NET Windows Applications, USA, O'Reilly & Associates, Inc

� http://msdn.microsoft.com