0% found this document useful (0 votes)
67 views109 pages

Launches. You Can Choose From Start Window (Which Lets You Open A New or Existing Project), Most Recent Solution, or Empty Environment

The document describes the components and functions of the Visual Basic IDE called Visual Studio. Visual Studio consists of various components like the toolbar, menu bar, project explorer, properties window, form designer, toolbox, etc. It allows users to write, compile and debug code, and monitor resources. The document further explains how to create and manage projects, solutions, files and dependencies using the Solution Explorer window in Visual Studio.

Uploaded by

Ayush Rawat
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
67 views109 pages

Launches. You Can Choose From Start Window (Which Lets You Open A New or Existing Project), Most Recent Solution, or Empty Environment

The document describes the components and functions of the Visual Basic IDE called Visual Studio. Visual Studio consists of various components like the toolbar, menu bar, project explorer, properties window, form designer, toolbox, etc. It allows users to write, compile and debug code, and monitor resources. The document further explains how to create and manage projects, solutions, files and dependencies using the Solution Explorer window in Visual Studio.

Uploaded by

Ayush Rawat
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 109

The components of the IDE screen of Visual Basic.

IDE stands for Integrated Development


Environment. The main functions include writing, compiling and debugging code, monitoring
resources.
The IDE in VB (Visual Basic) is ‘Visual Studio’. It consists of the following components. Those
are
 Startup Page
 Toolbar
 Menu bar
 Project explorer
 Properties window
 Form layout window
 Object designer
 Form designer
 Toolbox
Startup Page:
On the menu bar, choose Tools > Options. Expand Environment, and then choose
Startup. In the On startup, open list, choose what you want to happen after Visual Studio
launches. You can choose from Start window (which lets you open a new or existing project),
most recent solution, or Empty environment.

New Project Dialog Box: Allows you to select the type of project that you want to create.
If there is currently another project open, you'll be asked to save any changes before the new
project is created.
Open existing project: Open Visual Studio. On the start window, select Open a project or
solution. Visual Studio opens an instance of File Explorer, where you can browse to your
solution or project, and then select it to open it.
Recent Project: Open Visual Studio 2019 version 16.8 or later. On the start window, select
Open a recent or solution. Visual Studio opens an instance of File Explorer, where you can
browse to your solution or project, and then select it to recent project to open it.
Menu Bar:

Follow these steps to unhide the menu bar in VS Code:


1. From the sidebar, click on the three horizontal line toggle button. Next, select the View
option, and then choose Appearance.
2. From the sub-menu, check the Show Menu Bar option. Check the Show Menu Bar
option.

Add, remove, or move a menu on the menu bar


1. On the menu bar, choose Tools > Customize.

The Customize dialog box opens.

2. On the Commands tab, leave the Menu bar option button selected, leave Menu


Bar selected in the list next to that option, and then perform one of the following
sets of steps:

 To add a menu, choose the Add New Menu button, choose the Modify


Selection button, and then name the menu that you want to add.
 To remove a menu, choose it in the Controls list, and then choose
the Delete button.
 To move a menu within the menu bar, choose the menu in the Controls list,
and then choose the Move Up or Move Down button.

Add, remove, or move a toolbar


1. On the menu bar, choose Tools > Customize.

The Customize dialog box opens.

2. On the Toolbar tab, perform one of the following sets of steps:

 To add a toolbar, choose the New button, specify a name for the toolbar that
you want to add, and then choose the OK button.
 To remove a custom toolbar, choose it in the Toolbars list, and then choose
the Delete button.

 Important

You can delete toolbars that you create but not default toolbars.
 To move a toolbar to a different docking location, choose it in
the Toolbars list, choose the Modify Selection button, and then choose a
location in the list that appears.

You can also drag a toolbar by its left edge to move it anywhere in the main
docking area.

 Note

For more information about how to improve the usability and accessibility of
toolbars, see How to: Set IDE accessibility options.

Customize a menu or a toolbar


 Warning

After you customize a toolbar or menu, make sure that its check box remains selected in
the Customize dialog box. Otherwise, your changes won't persist after you close and
reopen Visual Studio.

1. On the menu bar, choose Tools > Customize.

The Customize dialog box opens.

2. On the Commands tab, choose the option button for the type of element that you
want to customize.
3. In the list for that type of element, choose the menu or toolbar that you want to
customize, and then perform one of the following sets of steps:

 To add a command, choose the Add Command button.

In the Add Command dialog box, choose an item in the Categories list,


choose an item in the Commands list, and then choose the OK button.

 To delete a command, choose it in the Controls list, and then choose


the Delete button.
 To reorder commands, choose a command in the Controls list, and then
choose the Move Up or Move Down button.
 To group commands under a horizontal line, choose the first command in
the Controls list, choose the Modify Selection button, and then
choose Begin a Group in the menu that appears.
Reset a menu or a toolbar
1. On the menu bar, choose Tools > Customize.

The Customize dialog box opens.

2. On the Commands tab, choose the option button for the type of element that you
want to reset.
3. In the list for that type of element, choose the menu or toolbar that you want to
reset.
4. Choose the Modify Selection button, and then choose Reset in the menu that
appears.

You can also reset all menus and toolbars by choosing the Reset All button.

Solution Explorer

You can use Solution Explorer to create & manage your solutions and projects and to
view & interact with your code. In this article, we'll cover how to open Solution Explorer
if you inadvertently close it. Then, we'll describe the Solution Explorer user interface (UI)
in detail.

Open Solution Explorer


By default, the Solution Explorer tool window appears as a pane in the upper-right side
of the Visual Studio integrated development environment (IDE). If you don't see the
Solution Explorer tool window, you can open it from the Visual Studio menu bar by
using View > Solution Explorer, or by pressing Ctrl+Alt+L.

Solution Explorer tool window


Let's take a look at the Solution Explorer tool window and its UI (user interface). We'll
start with an annotated screenshot of an open C# console solution that has two
projects.
The following table is a text-equivalent of the annotated screenshot, but with a few
handy links you can use to learn more.

UI element Action

Toolbar Control how your files appear

Search bar Search for specific files and file types

Main window View and manage your files, projects, & solutions

Solution node Manage your solution(s)

Project node Manage your project(s)

Dependencies node Manage your solution & project dependencies

Program node View, edit, and manage your program or application (app)

Git Changes tab Use Git & GitHub within Visual Studio to collaborate on projects with your team

Solution Explorer toolbar


To continue, let's take a closer look at the toolbar in Solution Explorer.

The toolbar contains the following UI elements, from left to right:

UI element Action

Back button Toggle between search results

Forward button Toggle between search results

Home button Return to the default view

Switch Views button Switch between solutions and available views

Pending Changes Filter button & drop- View open files or files with pending changes
down menu

Sync with Active Document button Locate a file from the code editor

Refresh button (conditional) Appears only when you select a dependency, such as a


function or a package

Collapse All button Collapse the file view in the main window


UI element Action

Show All Files button View all files, including unloaded projects

Properties button View and change settings for specific files and components

Preview Selected Items button View a selected file or component in the code editor

Solution Explorer context menu


In Solution Explorer, there are several options that you can interact with by using the
right-click context menu. The context-specific options that appear depend on whether
you select a Solution node or a Project node.

Solution node context menu options

The following screenshot for a C# console app shows the context menu options that
appear when you right-click the Solution node.

What you see in the context menu from the Solution node also depends on your
project type, programming language, or platform. The following screenshot highlights
the following extra options for a C# app: Project Dependencies, Project Build
Order, Set Startup Projects, and a Git fly-out menu. These extra options typically
appear when you add another project to a solution and then add it to a repo.

Project node context menu options

The following screenshot for a C# console app shows the context menu options that
appear when you right-click the Project node.

What you see in the context menu from the Project node also depends on your project
type, programming language, or platform. The following screenshot highlights the
following extra option for a C# app: a Build Dependencies fly-out menu. Extra options
typically appear when you add another project to a solution and then add it to a repo.
The Add context menu fly-out
In the Solution Explorer context menu, one of the most useful options is the Add fly-out
menu. From it, you can add another project to a solution. You can also add an item to a
project, and more.

You can view the Add fly-out menu from either the Solution node, the Project node, or


the Dependencies node. The options vary, depending on which node you use.

For a tutorial that walks you through how to add items and projects by using the
context menu in Solution Explorer, see the Introduction to projects and solutions page.

Toolbox
Applies to:  Visual Studio  Visual Studio for Mac  Visual Studio Code

The Toolbox window displays controls that you can add to Visual Studio projects. To
open Toolbox, choose View > Toolbox from the menu bar, or press Ctrl+Alt+X.

You can drag and drop different controls onto the surface of the designer you are using,
and resize and position the controls.

Toolbox appears in conjunction with designer views, such as the designer view of a
XAML file or a Windows Forms App project. Toolbox displays only those controls that
can be used in the current designer. You can search within Toolbox to further filter the
items that appear.

 Note

For some project types, Toolbox may not show any items.

The .NET version that your project targets also affects the set of controls visible in
Toolbox. You can change the target framework version from the project's property
pages, if necessary. Select the project node in Solution Explorer, and then on the menu
bar, choose Project > projectname Properties. On the Application tab, use the Target
framework drop-down.

Manage the Toolbox window and its controls


By default, Toolbox is collapsed along the left side of the Visual Studio IDE and appears
when the cursor is moved over it. You can pin Toolbox (by clicking the Pin icon on its
toolbar) so that it remains open when you move the cursor. You can also undock
the Toolbox window and drag it anywhere on your screen. You can dock, undock, and
hide Toolbox by right-clicking its toolbar and selecting one of the options.

 Tip

If the Toolbox no longer appears as collapsed along the left side of the Visual Studio
IDE, you can add it back by choosing Window > Reset Window Layout from the menu
bar.

You can rearrange the items in a Toolbox tab or add custom tabs and items by using
the following commands on the right-click context menu:

 Rename Item - Renames the selected item.

 List View - Shows the controls in a vertical list. If unchecked, the controls appear
horizontally.

 Show All - Shows all possible controls (not just the ones that apply to the current
designer).

 Choose Items - Opens the Choose Toolbox Items dialog box so that you can
specify the items that appear in the Toolbox. You can show or hide an item by
selecting or clearing its check box.

 Sort Items Alphabetically - Sorts the items by name.

 Reset Toolbar - Restores the default Toolbox settings and items.

 Add Tab - Adds a new Toolbox tab.

 Move Up - Moves the selected item up.


 Move Down - Moves the selected item down.

Create and distribute custom Toolbox controls


You can create custom Toolbox controls, starting either with a project template that's
based on Windows Presentation Foundation or on Windows Forms. You can then
distribute your custom control to your teammates, or publish it on the web by using
the Toolbox Controls Installer.

Properties window
Applies to:  Visual Studio  Visual Studio for Mac  Visual Studio Code

Use this window to view and change the design-time properties and events of selected
objects that are located in editors and designers. You can also use
the Properties window to edit and view file, project, and solution properties. You can
find Properties Window on the View menu. You can also open it by pressing F4 or by
typing Properties in the search box.

The Properties window displays different types of editing fields, depending on the


needs of a particular property. These edit fields include edit boxes, drop-down lists, and
links to custom editor dialog boxes. Properties shown in gray are read-only.

UIElement List
Object name
Lists the currently selected object or objects. Only objects from the active editor or
designer are visible. When you select multiple objects, only properties common to all
selected objects appear.

Categorized
Lists all properties and property values for the selected object, by category. You can
collapse a category to reduce the number of visible properties. When you expand or
collapse a category, you see a plus (+) or minus (-) to the left of the category name.
Categories are listed alphabetically.

Alphabetical
Alphabetically sorts all design-time properties and events for selected objects. To edit
an undimmed property, click in the cell to its right and enter changes.
Property Pages
Displays the Property Pages dialog box or Project Designer for the selected item.
Property Pages displays a subset, the same or a superset of the properties available in
the Properties window. Use this button to view and edit properties related to your
project's active configuration.

Properties
Displays the properties for an object. Many objects also have events that can be viewed
using the Properties window.

Sort by Property Source


Groups properties by source, such as inheritance, applied styles, and bindings. Only
available when editing XAML files in the designer.

Events
Displays the events for an object.

 Note

This Properties window toolbar control is only available when a form or control


designer is active in the context of a Visual C# project. When editing XAML files, events
appear on a separate tab of the properties window.

Messages
Lists all Windows messages. Allows you to add or delete specified handler functions for
the messages provided for the selected class.

 Note

This Properties window toolbar control is only available when Class View is the active


window in the context of a Visual C++ project.

Overrides
Lists all virtual functions for the selected class and allows you to add or delete overriding
functions.

 Note

This Properties window toolbar control is only available when Class View is the active


window in the context of a Visual C++ project.
Description pane
Shows the property type and a short description of the property. You can turn the
description of the property off and on using the Description command on the shortcut
menu.

 Note

This Properties window toolbar control is not available when editing XAML files in the
designer.

Thumbnail view
Shows a visual representation of the currently selected element when editing XAML files
in the designer.

Search
Provides a Search function for properties and events when editing XAML files in the
designer. The search box responds to partial word searches and updates search results
as you type.

VB.Net - Forms
Let's start with creating a Window Forms Application by following the following steps in
Microsoft Visual Studio - File → New Project → Windows Forms Applications
Finally, select OK, Microsoft Visual Studio creates your project and displays following
window Form with a name Form1.
Visual Basic Form is the container for all the controls that make up the user interface.
Every window you see in a running visual basic application is a form, thus the terms
form and window describe the same entity. Visual Studio creates a default form for you
when you create a Windows Forms Application.
Every form will have title bar on which the form's caption is displayed and there will be
buttons to close, maximize and minimize the form shown below −
If you click the icon on the top left corner, it opens the control menu, which contains the
various commands to control the form like to move control from one place to another
place, to maximize or minimize the form or to close the form.

Form Properties
Following table lists down various important properties related to a form. These
properties can be set or read during application execution. You can refer to Microsoft
documentation for a complete list of properties associated with a Form control −

S.N Properties Description

1
AcceptButton The button that's automatically activated when you press
Enter, no matter which control has the focus at the time.
Usually the OK button on a form is set as AcceptButton for
a form.

2
CancelButton The button that's automatically activated when you hit the
Esc key.
Usually, the Cancel button on a form is set as
CancelButton for a form.

3
AutoScale This Boolean property determines whether the controls you
place on the form are automatically scaled to the height of
the current font. The default value of this property is True.
This is a property of the form, but it affects the controls on
the form.

4
AutoScroll This Boolean property indicates whether scroll bars will be
automatically attached to the form if it is resized to a point
that not all its controls are visible.

5
AutoScrollMinSize This property lets you specify the minimum size of the form,
before the scroll bars are attached.

6
AutoScrollPosition The AutoScrollPosition is the number of pixels by which the
two scroll bars were displaced from their initial locations.

7
BackColor Sets the form background color.

8
BorderStyle The BorderStyle property determines the style of the form's
border and the appearance of the form −
 None − Borderless window that can't be resized.
 Sizable − This is default value and will be used for
resizable window that's used for displaying regular
forms.
 Fixed3D − Window with a visible border, "raised"
relative to the main area. In this case, windows can't
be resized.
 FixedDialog − A fixed window, used to create dialog
boxes.
 FixedSingle − A fixed window with a single line
border.
 FixedToolWindow − A fixed window with a Close
button only. It looks like the toolbar displayed by the
drawing and imaging applications.
 SizableToolWindow − Same as the
FixedToolWindow but resizable. In addition, its
caption font is smaller than the usual.

9
ControlBox By default, this property is True and you can set it to False
to hide the icon and disable the Control menu.

10
Enabled If True, allows the form to respond to mouse and keyboard
events; if False, disables form.

11
Font This property specify font type, style, size

12
HelpButton Determines whether a Help button should be displayed in
the caption box of the form.

13
Height This is the height of the Form in pixels.

14
MinimizeBox By default, this property is True and you can set it to False
to hide the Minimize button on the title bar.

15
MaximizeBox By default, this property is True and you can set it to False
to hide the Maximize button on the title bar.

16
MinimumSize This specifies the minimum height and width of the window
you can minimize.

17
MaximumSize This specifies the maximum height and width of the window
you maximize.

18
Name This is the actual name of the form.

19
StartPosition This property determines the initial position of the form
when it's first displayed. It will have any of the following
values −
 CenterParent − The form is centered in the area of
its parent form.
 CenterScreen − The form is centered on the
monitor.
 Manual − The location and size of the form will
determine its starting position.
 WindowsDefaultBounds − The form is positioned
at the default location and size determined by
Windows.
 WindowsDefaultLocation − The form is positioned
at the Windows default location and has the
dimensions you've set at design time.

20
Text The text, which will appear at the title bar of the form.

21
Top, Left These two properties set or return the coordinates of the
form's top-left corner in pixels.

22
TopMost This property is a True/False value that lets you specify
whether the form will remain on top of all other forms in
your application. Its default property is False.

23
Width This is the width of the form in pixel.

Form Methods
The following are some of the commonly used methods of the Form class. You can
refer to Microsoft documentation for a complete list of methods associated with forms
control −

Sr.No Method Name & Description


.

1
Activate
Activates the form and gives it focus.

2
ActivateMdiChild
Activates the MDI child of a form.

3
AddOwnedForm
Adds an owned form to this form.
4
BringToFront
Brings the control to the front of the z-order.

5
CenterToParent
Centers the position of the form within the bounds of the parent form.

6
CenterToScreen
Centers the form on the current screen.

7
Close
Closes the form.

8
Contains
Retrieves a value indicating whether the specified control is a child of the
control.

9
Focus
Sets input focus to the control.

10
Hide
Conceals the control from the user.

11
Refresh
Forces the control to invalidate its client area and immediately redraw itself and
any child controls.

12
Scale(SizeF)
Scales the control and all child controls by the specified scaling factor.

13
ScaleControl
Scales the location, size, padding, and margin of a control.
14
ScaleCore
Performs scaling of the form.

15
Select
Activates the control.

16
SendToBack
Sends the control to the back of the z-order.

17
SetAutoScrollMargin
Sets the size of the auto-scroll margins.

18
SetDesktopBounds
Sets the bounds of the form in desktop coordinates.

19
SetDesktopLocation
Sets the location of the form in desktop coordinates.

20
SetDisplayRectLocation
Positions the display window to the specified value.

21
Show
Displays the control to the user.

22
ShowDialog
Shows the form as a modal dialog box.

Form Events
Following table lists down various important events related to a form. You can refer to
Microsoft documentation for a complete list of events associated with forms control −
Sr.No Event Description
.

1
Activated Occurs when the form is activated in code or by the
user.

2
Click Occurs when the form is clicked.

3
Closed Occurs before the form is closed.

4
Closing Occurs when the form is closing.

5
DoubleClick Occurs when the form control is double-clicked.

6
DragDrop Occurs when a drag-and-drop operation is completed.

7
Enter Occurs when the form is entered.

8
GotFocus Occurs when the form control receives focus.

9
HelpButtonClicked Occurs when the Help button is clicked.

10
KeyDown Occurs when a key is pressed while the form has focus.

11
KeyPress Occurs when a key is pressed while the form has focus.

12
KeyUp Occurs when a key is released while the form has focus.

13
Load Occurs before a form is displayed for the first time.

14
LostFocus Occurs when the form loses focus.

15
MouseDown Occurs when the mouse pointer is over the form and a
mouse button is pressed.

16
MouseEnter Occurs when the mouse pointer enters the form.

17
MouseHover Occurs when the mouse pointer rests on the form.

18
MouseLeave Occurs when the mouse pointer leaves the form.

19
MouseMove Occurs when the mouse pointer is moved over the form.

20
MouseUp Occurs when the mouse pointer is over the form and a
mouse button is released.

21
MouseWheel Occurs when the mouse wheel moves while the control
has focus.

22
Move Occurs when the form is moved.

23
Resize Occurs when the control is resized.

24
Scroll Occurs when the user or code scrolls through the client
area.

25
Shown Occurs whenever the form is first displayed.

26
VisibleChanged Occurs when the Visible property value changes.

Example
Following is an example, which shows how we create two buttons at the time of form
load event and different properties are being set at the same time.
Because Form1 is being referenced within its own event handler, so it will be written
as Me instead of using its name, but if we access the same form inside any other
control's event handler, then it will be accessed using its name Form1.
Let's double click on the Form and put the follow code in the opened window.
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
' Create two buttons to use as the accept and cancel buttons.
Dim button1 As New Button()
Dim button2 As New Button()
' Set the text of button1 to "OK".

button1.Text = "OK"
' Set the position of the button on the form.
button1.Location = New Point(10, 10)
' Set the text of button2 to "Cancel".

button2.Text = "Cancel"
' Set the position of the button based on the location of button1.
button2.Location = _
New Point(button1.Left, button1.Height + button1.Top + 10)
' Set the caption bar text of the form.

Me.Text = "tutorialspoint.com"
' Display a help button on the form.
Me.HelpButton = True
' Define the border style of the form to a dialog box.

Me.FormBorderStyle = FormBorderStyle.FixedDialog
' Set the MaximizeBox to false to remove the maximize box.
Me.MaximizeBox = False
' Set the MinimizeBox to false to remove the minimize box.

Me.MinimizeBox = False
' Set the accept button of the form to button1.
Me.AcceptButton = button1
' Set the cancel button of the form to button2.

Me.CancelButton = button2
' Set the start position of the form to the center of the screen.
Me.StartPosition = FormStartPosition.CenterScreen
' Set window width and height

Me.Height = 300
Me.Width = 560
' Add button1 to the form.

Me.Controls.Add(button1)
' Add button2 to the form.
Me.Controls.Add(button2)
End Sub
End Class
When the above code is executed and run using Start button available at the Microsoft
Visual Studio tool bar, it will show the following window −

VB.Net - TextBox Control


Text box controls allow entering text on a form at runtime. By default, it takes a single
line of text, however, you can make it accept multiple texts and even add scroll bars to
it.
Let's create a text box by dragging a Text Box control from the Toolbox and dropping it
on the form.
The Properties of the TextBox Control
The following are some of the commonly used properties of the TextBox control −

Sr.No Property & Description


.

1
AcceptsReturn
Gets or sets a value indicating whether pressing ENTER in a multiline TextBox
control creates a new line of text in the control or activates the default button for
the form.

2
AutoCompleteCustomSource
Gets or sets a custom System.Collections.Specialized.StringCollection to use
when the AutoCompleteSourceproperty is set to CustomSource.

3
AutoCompleteMode
Gets or sets an option that controls how automatic completion works for the
TextBox.

4
AutoCompleteSource
Gets or sets a value specifying the source of complete strings used for
automatic completion.

5
CharacterCasing
Gets or sets whether the TextBox control modifies the case of characters as
they are typed.

6
Font
Gets or sets the font of the text displayed by the control.

7
FontHeight
Gets or sets the height of the font of the control.

8
ForeColor
Gets or sets the foreground color of the control.

9
Lines
Gets or sets the lines of text in a text box control.

10
Multiline
Gets or sets a value indicating whether this is a multiline TextBox control.

11
PasswordChar
Gets or sets the character used to mask characters of a password in a single-
line TextBox control.

12
ReadOnly
Gets or sets a value indicating whether text in the text box is read-only.

13
ScrollBars
Gets or sets which scroll bars should appear in a multiline TextBox control. This
property has values −
 None
 Horizontal
 Vertical
 Both

14
TabIndex
Gets or sets the tab order of the control within its container.

15
Text
Gets or sets the current text in the TextBox.

16
TextAlign
Gets or sets how text is aligned in a TextBox control. This property has values

 Left
 Right
 Center

17
TextLength
Gets the length of text in the control.

18
WordWrap
Indicates whether a multiline text box control automatically wraps words to the
beginning of the next line when necessary.

The Methods of the TextBox Control


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

Sr.No Method Name & Description


.

1
AppendText
Appends text to the current text of a text box.
2
Clear
Clears all text from the text box control.

3
Copy
Copies the current selection in the text box to the Clipboard.

4
Cut
Moves the current selection in the text box to the Clipboard.

5
Paste
Replaces the current selection in the text box with the contents of
the Clipboard.

6
Paste(String)
Sets the selected text to the specified text without clearing the undo buffer.

7
ResetText
Resets the Text property to its default value.

8
ToString
Returns a string that represents the TextBoxBase control.

9
Undo
Undoes the last edit operation in the text box.

Events of the TextBox Control


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

Sr.No. Event & Description

1
Click
Occurs when the control is clicked.

2
DoubleClick
Occurs when the control is double-clicked.

3
TextAlignChanged
Occurs when the TextAlign property value changes.

Example
In this example, we create three text boxes and use the Click event of a button to
display the entered text using a message box. Take the following steps −
 Drag and drop three Label controls and three TextBox controls on the form.
 Change the texts on the labels to: Name, Organization and Comments,
respectively.
 Change the names of the text boxes to txtName, txtOrg and txtComment,
respectively.
 Drag and drop a button control on the form. Set its name to btnMessage and its
text property to 'Send Message'.
 Click the button to add the Click event in the code window and add the following
code.
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) _
Handles MyBase.Load
' Set the caption bar text of the form.
Me.Text = "tutorialspont.com"
End Sub

Private Sub btnMessage_Click(sender As Object, e As EventArgs) _


Handles btnMessage.Click
MessageBox.Show("Thank you " + txtName.Text + " from " + txtOrg.Text)
End Sub
End Class
When the above code is executed and run using Start button available at the Microsoft
Visual Studio tool bar, it will show the following window −
Clicking the Send Message button would show the following message box −

VB.Net - Label Control


The Label control represents a standard Windows label. It is generally used to display
some informative text on the GUI which is not changed during runtime.
Let's create a label by dragging a Label control from the Toolbox and dropping it on the
form.
Properties of the Label Control
The following are some of the commonly used properties of the Label control −

Sr.No Property & Description


.

1
Autosize
Gets or sets a value specifying if the control should be automatically resized to
display all its contents.

2
BorderStyle
Gets or sets the border style for the control.

3
FlatStyle
Gets or sets the flat style appearance of the Label control

4
Font
Gets or sets the font of the text displayed by the control.

5
FontHeight
Gets or sets the height of the font of the control.

6
ForeColor
Gets or sets the foreground color of the control.

7
PreferredHeight
Gets the preferred height of the control.

8
PreferredWidth
Gets the preferred width of the control.

9
TabStop
Gets or sets a value indicating whether the user can tab to the Label. This
property is not used by this class.

10
Text
Gets or sets the text associated with this control.

11
TextAlign
Gets or sets the alignment of text in the label.

Methods of the Label Control


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

Sr.No Method Name & Description


.

1
GetPreferredSize
Retrieves the size of a rectangular area into which a control can be fitted.

2
Refresh
Forces the control to invalidate its client area and immediately redraw itself and
any child controls.

3
Select
Activates the control.

4
Show
Displays the control to the user.

5
ToString
Returns a String that contains the name of the control.

Events of the Label Control


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

Sr.No Event & Description


.

1
AutoSizeChanged
Occurs when the value of the AutoSize property changes.

2
Click
Occurs when the control is clicked.

3
DoubleClick
Occurs when the control is double-clicked.

4
GotFocus
Occurs when the control receives focus.

5
Leave
Occurs when the input focus leaves the control.

6
LostFocus
Occurs when the control loses focus.

7
TabIndexChanged
Occurs when the TabIndex property value changes.

8
TabStopChanged
Occurs when the TabStop property changes.

9
TextChanged
Occurs when the Text property value changes.

Consult Microsoft documentation for detailed list of properties, methods and events of
the Label control.

Example
Following is an example, which shows how we can create two labels. Let us create the
first label from the designer view tab and set its properties from the properties window.
We will use the Click and the DoubleClick events of the label to move the first label and
change its text and create the second label and add it to the form, respectively.
Take the following steps −
 Drag and drop a Label control on the form.
 Set the Text property to provide the caption "This is a Label Control".
 Set the Font property from the properties window.
 Click the label to add the Click event in the code window and add the following
codes.
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) _
Handles MyBase.Load

' Create two buttons to use as the accept and cancel buttons.
' Set window width and height
Me.Height = 300
Me.Width = 560
' Set the caption bar text of the form.
Me.Text = "tutorialspont.com"
' Display a help button on the form.
Me.HelpButton = True
End Sub

Private Sub Label1_Click(sender As Object, e As EventArgs) _


Handles Label1.Click
Label1.Location = New Point(50, 50)
Label1.Text = "You have just moved the label"
End Sub
Private Sub Label1_DoubleClick(sender As Object, e As EventArgs)
Handles Label1.DoubleClick
Dim Label2 As New Label
Label2.Text = "New Label"
Label2.Location = New Point(Label1.Left, Label1.Height + _
Label1.Top + 25)
Me.Controls.Add(Label2)
End Sub
End Class
When the above code is executed and run using Start button available at the Microsoft
Visual Studio tool bar, it will show the following window −

Clicking and double clicking the label would produce the following effect −
VB.Net - Button Control
The Button control represents a standard Windows button. It is generally used to
generate a Click event by providing a handler for the Click event.
Let's create a label by dragging a Button control from the Toolbox ad dropping it on the
form.

Properties of the Button Control


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

Sr.No Property & Description


.

1
AutoSizeMode
Gets or sets the mode by which the Button automatically resizes itself.

2
BackColor
Gets or sets the background color of the control.

3
BackgroundImage
Gets or sets the background image displayed in the control.

4
DialogResult
Gets or sets a value that is returned to the parent form when the button is
clicked. This is used while creating dialog boxes.

5
ForeColor
Gets or sets the foreground color of the control.

6
Image
Gets or sets the image that is displayed on a button control.

7
Location
Gets or sets the coordinates of the upper-left corner of the control relative to
the upper-left corner of its container.

8
TabIndex
Gets or sets the tab order of the control within its container.

9
Text
Gets or sets the text associated with this control.
Methods of the Button Control
The following are some of the commonly used methods of the Button control −

Sr.No Method Name & Description


.

1
GetPreferredSize
Retrieves the size of a rectangular area into which a control can be fitted.

2
NotifyDefault
Notifies the Button whether it is the default button so that it can adjust its
appearance accordingly.

3
Select
Activates the control.

4
ToString
Returns a String containing the name of the Component, if any. This method
should not be overridden.

Events of the Button Control


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

Sr.No Event & Description


.

1
Click
Occurs when the control is clicked.

2
DoubleClick
Occurs when the user double-clicks the Button control.

3
GotFocus
Occurs when the control receives focus.

4
TabIndexChanged
Occurs when the TabIndex property value changes.

5
TextChanged
Occurs when the Text property value changes.

6
Validated
Occurs when the control is finished validating.

Consult Microsoft documentation for detailed list of properties, methods and events of
the Button control.

Example
In the following example, we create three buttons. In this example, let us −
 Set captions for the buttons
 Set some image for the button
 Handle the click events of each buttons
Take following steps −
 Drag and drop a Label control on the form.
 Set the Text property to provide the caption "Tutorials Point".
 Drag and drop three buttons on the form.
 Using the properties window, change the Name properties of the buttons to
btnMoto, btnLogo and btnExit respectively.
 Using the properties window, change the Text properties of the buttons to Show
Moto, Show Logo and Exit respectively.
 Drag and Drop another button, using the properties window, set its Image
property and name it btnImage.
At this stage, the form looks like −
Click the form and add following code in the code editor −
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
' Set the caption bar text of the form.
Me.Text = "tutorialspont.com"
btnImage.Visible = False
End Sub

Private Sub btnMoto_Click(sender As Object, e As EventArgs) Handles btnMoto.Click


btnImage.Visible = False
Label1.Text = "Simple Easy Learning"
End Sub

Private Sub btnExit_Click(sender As Object, e As EventArgs) Handles btnExit.Click


Application.Exit()
End Sub

Private Sub btnLogo_Click(sender As Object, e As EventArgs) Handles btnLogo.Click


Label1.Visible = False
btnImage.Visible = True
End Sub
End Class
Clicking the first button, displays −
Clicking the second button displays −

Clicking the third button, exits the application.

VB.Net - 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.

You can populate the list box items either from the properties window or at runtime. To
add items to a ListBox, select the ListBox control and get to the properties window, for
the properties of this control. Click the ellipses (...) button next to the Items property.
This opens the String Collection Editor dialog box, where you can enter the values one
at a line.

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
Sorted
Gets or sets a value indicating whether the items in the list box are sorted
alphabetically.

17
Text
Gets or searches for the text of the currently selected item in the list box.

18
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.

8
OnSelectedValueChanged
Raises the SelectedValueChanged 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.

Consult Microsoft documentation for detailed list of properties, methods and events of
the ListBox control.

Example 1
In the following example, let us add a list box at design time and add items on it at
runtime.
Take the following steps −
 Drag and drop two labels, a button and a ListBox control on the form.
 Set the Text property of the first label to provide the caption "Choose your
favourite destination for higher studies".
 Set the Text property of the second label to provide the caption "Destination". The
text on this label will change at runtime when the user selects an item on the list.
 Click the listbox and the button controls to add the following codes in the code
editor.
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
' Set the caption bar text of the form.
Me.Text = "tutorialspont.com"
ListBox1.Items.Add("Canada")
ListBox1.Items.Add("USA")
ListBox1.Items.Add("UK")
ListBox1.Items.Add("Japan")
ListBox1.Items.Add("Russia")
ListBox1.Items.Add("China")
ListBox1.Items.Add("India")
End Sub

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


MsgBox("You have selected " + ListBox1.SelectedItem.ToString())
End Sub
Private Sub ListBox1_SelectedIndexChanged(sender As Object, e As EventArgs)
Handles ListBox1.SelectedIndexChanged
Label2.Text = ListBox1.SelectedItem.ToString()
End Sub
End Class
When the above code is executed and run using Start button available at the Microsoft
Visual Studio tool bar, it will show the following window −

When the user chooses a destination, the text in the second label changes −

Clicking the Select button displays a message box with the user's choice −
Example 2
In this example, we will fill up a list box with items, retrieve the total number of items in
the list box, sort the list box, remove some items and clear the entire list box.
Design the Form −

Add the following code in the code editor window −


Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
' Set the caption bar text of the form.
Me.Text = "tutorialspont.com"
' creating multi-column and multiselect list box
ListBox1.MultiColumn = True
ListBox1.SelectionMode = SelectionMode.MultiExtended
End Sub

'populates the list


Private Sub Button1_Click_1(sender As Object, e As EventArgs) _
Handles Button1.Click
ListBox1.Items.Add("Safety")
ListBox1.Items.Add("Security")
ListBox1.Items.Add("Governance")
ListBox1.Items.Add("Good Music")
ListBox1.Items.Add("Good Movies")
ListBox1.Items.Add("Good Books")
ListBox1.Items.Add("Education")
ListBox1.Items.Add("Roads")
ListBox1.Items.Add("Health")
ListBox1.Items.Add("Food for all")
ListBox1.Items.Add("Shelter for all")
ListBox1.Items.Add("Industrialisation")
ListBox1.Items.Add("Peace")
ListBox1.Items.Add("Liberty")
ListBox1.Items.Add("Freedom of Speech")
End Sub
'sorting the list
Private Sub Button2_Click(sender As Object, e As EventArgs) _
Handles Button2.Click
ListBox1.Sorted = True
End Sub

'clears the list


Private Sub Button3_Click(sender As Object, e As EventArgs) _
Handles Button3.Click
ListBox1.Items.Clear()
End Sub

'removing the selected item


Private Sub Button4_Click(sender As Object, e As EventArgs) _
Handles Button4.Click
ListBox1.Items.Remove(ListBox1.SelectedItem.ToString)
End Sub

'counting the numer of items


Private Sub Button5_Click(sender As Object, e As EventArgs) _
Handles Button5.Click
Label1.Text = ListBox1.Items.Count
End Sub

'displaying the selected item on the third label


Private Sub ListBox1_SelectedIndexChanged(sender As Object, e As EventArgs) _
Handles ListBox1.SelectedIndexChanged
Label3.Text = ListBox1.SelectedItem.ToString()
End Sub
End Class
When the above code is executed and run using Start button available at the Microsoft
Visual Studio tool bar, it will show the following window −

Fill the list and check workings of other buttons −

VB.Net - ComboBox Control


The ComboBox control is used to display a drop-down list of various items. It is a
combination of a text box in which the user enters an item and a drop-down list from
which the user selects an item.
Let's create a combo box by dragging a ComboBox control from the Toolbox and
dropping it on the form.
You can populate the list box items either from the properties window or at runtime. To
add items to a ComboBox, select the ComboBox control and go to the properties
window for the properties of this control. Click the ellipses (...) button next to the Items
property. This opens the String Collection Editor dialog box, where you can enter the
values one at a line.

Properties of the ComboBox Control


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

Sr.No Property & Description


.

1
AllowSelection
Gets a value indicating whether the list enables selection of list items.

2
AutoCompleteCustomSource
Gets or sets a custom System.Collections .Specialized.StringCollection to use
when the AutoCompleteSourceproperty is set to CustomSource.

3
AutoCompleteMode
Gets or sets an option that controls how automatic completion works for the
ComboBox.

4
AutoCompleteSource
Gets or sets a value specifying the source of complete strings used for
automatic completion.

5
DataBindings
Gets the data bindings for the control.

6
DataManager
Gets the CurrencyManager associated with this control.

7
DataSource
Gets or sets the data source for this ComboBox.

8
DropDownHeight
Gets or sets the height in pixels of the drop-down portion of the ComboBox.

9
DropDownStyle
Gets or sets a value specifying the style of the combo box.

10
DropDownWidth
Gets or sets the width of the of the drop-down portion of a combo box.

11
DroppedDown
Gets or sets a value indicating whether the combo box is displaying its drop-
down portion.

12
FlatStyle
Gets or sets the appearance of the ComboBox.

13
ItemHeight
Gets or sets the height of an item in the combo box.

14
Items
Gets an object representing the collection of the items contained in this
ComboBox.

15
MaxDropDownItems
Gets or sets the maximum number of items to be displayed in the drop-down
part of the combo box.

16
MaxLength
Gets or sets the maximum number of characters a user can enter in the
editable area of the combo box.

17
SelectedIndex
Gets or sets the index specifying the currently selected item.

18
SelectedItem
Gets or sets currently selected item in the ComboBox.

19
SelectedText
Gets or sets the text that is selected in the editable portion of a ComboBox.

20
SelectedValue
Gets or sets the value of the member property specified by the ValueMember
property.

21
SelectionLength
Gets or sets the number of characters selected in the editable portion of the
combo box.

22
SelectionStart
Gets or sets the starting index of text selected in the combo box.

23
Sorted
Gets or sets a value indicating whether the items in the combo box are sorted.

24
Text
Gets or sets the text associated with this control.

Methods of the ComboBox Control


The following are some of the commonly used methods of the ComboBox 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 combo box one at a time.

2
EndUpdate
Resumes drawing of a combo box, after it was turned off by the BeginUpdate
method.

3
FindString
Finds the first item in the combo box that starts with the string specified as an
argument.

4
FindStringExact
Finds the first item in the combo box that exactly matches the specified string.
5
SelectAll
Selects all the text in the editable area of the combo box.

Events of the ComboBox Control


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

Sr.No Event & Description


.

1
DropDown
Occurs when the drop-down portion of a combo box is displayed.

2
DropDownClosed
Occurs when the drop-down portion of a combo box is no longer visible.

3
DropDownStyleChanged
Occurs when the DropDownStyle property of the ComboBox has changed.

4
SelectedIndexChanged
Occurs when the SelectedIndex property of a ComboBox control has changed.

5
SelectionChangeCommitted
Occurs when the selected item has changed and the change appears in the
combo box.

Example
In this example, let us fill a combo box with various items, get the selected items in the
combo box and show them in a list box and sort the items.
Drag and drop a combo box to store the items, a list box to display the selected items,
four button controls to add to the list box with selected items, to fill the combo box, to
sort the items and to clear the combo box list, respectively.
Add a label control that would display the selected item.
Add the following code in the code editor window −
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
' Set the caption bar text of the form.
Me.Text = "tutorialspont.com"
End Sub

'sends the selected items to the list box


Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
If ComboBox1.SelectedIndex > -1 Then
Dim sindex As Integer
sindex = ComboBox1.SelectedIndex
Dim sitem As Object
sitem = ComboBox1.SelectedItem
ListBox1.Items.Add(sitem)
End If
End Sub

'populates the list


Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
ComboBox1.Items.Clear()
ComboBox1.Items.Add("Safety")
ComboBox1.Items.Add("Security")
ComboBox1.Items.Add("Governance")
ComboBox1.Items.Add("Good Music")
ComboBox1.Items.Add("Good Movies")
ComboBox1.Items.Add("Good Books")
ComboBox1.Items.Add("Education")
ComboBox1.Items.Add("Roads")
ComboBox1.Items.Add("Health")
ComboBox1.Items.Add("Food for all")
ComboBox1.Items.Add("Shelter for all")
ComboBox1.Items.Add("Industrialisation")
ComboBox1.Items.Add("Peace")
ComboBox1.Items.Add("Liberty")
ComboBox1.Items.Add("Freedom of Speech")
ComboBox1.Text = "Select from..."
End Sub
'sorting the list

Private Sub Button3_Click(sender As Object, e As EventArgs)


ComboBox1.Sorted = True
End Sub
'clears the list

Private Sub Button4_Click(sender As Object, e As EventArgs)


ComboBox1.Items.Clear()
End Sub
'displaying the selected item on the label

Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) _


Handles ListBox1.SelectedIndexChanged
Label1.Text = ComboBox1.SelectedItem.ToString()
End Sub
End Class
When the above code is executed and run using Start button available at the Microsoft
Visual Studio tool bar, it will show the following window −
Click on various buttons to check the actions performed by each −

VB.Net - RadioButton 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


.

1
PerformClick
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

1
AppearanceChanged
Occurs when the value of the Appearance property of the RadioButton control is
changed.

2
CheckedChanged
Occurs when the value of the Checked property of the RadioButton control is
changed.
Consult Microsoft documentation for detailed list of properties, methods and events of
the RadioButton control.

Example
In the following example, let us create two groups of radio buttons and use their
CheckedChanged events for changing the BackColor and ForeColor property of the
form.

Let's double click on the radio buttons and put the follow code in the opened window.
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
' Set the caption bar text of the form.
Me.Text = "tutorialspont.com"
End Sub

Private Sub RadioButton1_CheckedChanged(sender As Object, _


e As EventArgs) Handles RadioButton1.CheckedChanged
Me.BackColor = Color.Red
End Sub

Private Sub RadioButton2_CheckedChanged(sender As Object, _


e As EventArgs) Handles RadioButton2.CheckedChanged
Me.BackColor = Color.Green
End Sub

Private Sub RadioButton3_CheckedChanged(sender As Object, _


e As EventArgs) Handles RadioButton3.CheckedChanged
Me.BackColor = Color.Blue
End Sub
Private Sub RadioButton4_CheckedChanged(sender As Object, _
e As EventArgs) Handles RadioButton4.CheckedChanged
Me.ForeColor = Color.Black
End Sub

Private Sub RadioButton5_CheckedChanged(sender As Object, _


e As EventArgs) Handles RadioButton5.CheckedChanged
Me.ForeColor = Color.White
End Sub

Private Sub RadioButton6_CheckedChanged(sender As Object, _


e As EventArgs) Handles RadioButton6.CheckedChanged
Me.ForeColor = Color.Red
End Sub
End Class
When the above code is executed and run using Start button available at the Microsoft
Visual Studio tool bar, it will show the following window −

VB.Net - 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 ThreeState property of the check box is set to be True.

Properties of the CheckBox Control


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

Sr.No Property & Description


.

1
Appearance
Gets or sets a value determining the appearance of the check box.

2
AutoCheck
Gets or sets a value indicating whether the Checked or CheckedState value
and the appearance of the control automatically change when the check box is
selected.

3
CheckAlign
Gets or sets the horizontal and vertical alignment of the check mark on the
check box.

4
Checked
Gets or sets a value indicating whether the check box is selected.

5
CheckState
Gets or sets the state of a check box.

6
Text
Gets or sets the caption of a check box.

7
ThreeState
Gets or sets a value indicating whether or not a check box should allow three
check states rather than two.

Methods of the CheckBox Control


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

Sr.No Method Name & Description


.

1
OnCheckedChanged
Raises the CheckedChanged event.

2
OnCheckStateChanged
Raises the CheckStateChanged event.

3
OnClick
Raises the OnClick event.

Events of the CheckBox Control


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

Sr.No Event & Description


.

1
AppearanceChanged
Occurs when the value of the Appearance property of the check box is
changed.

2
CheckedChanged
Occurs when the value of the Checked property of the CheckBox control is
changed.

3
CheckStateChanged
Occurs when the value of the CheckState property of the CheckBox control is
changed.

Consult Microsoft documentation for detailed list of properties, methods and events of
the CheckBox control.

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 −
Let's put the following code in the code editor window −
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) _
Handles MyBase.Load
' Set the caption bar text of the form.
Me.Text = "tutorialspoint.com"
Label1.Visible = False
TextBox1.Visible = False
TextBox1.Multiline = True
End Sub

Private Sub Button1_Click(sender As Object, e As EventArgs) _


Handles Button1.Click
Dim str As String
str = " "

If CheckBox1.Checked = True Then


str &= CheckBox1.Text
str &= " "
End If

If CheckBox2.Checked = True Then


str &= CheckBox2.Text
str &= " "
End If

If CheckBox3.Checked = True Then


str &= CheckBox3.Text
str &= " "
End If
If CheckBox4.Checked = True Then
str &= TextBox1.Text
str &= " "
End If
If str <> Nothing Then
MsgBox(str + vbLf + "Thank you")
End If
End Sub

Private Sub CheckBox4_CheckedChanged(sender As Object, _


e As EventArgs) Handles CheckBox4.CheckedChanged
Label1.Visible = True
TextBox1.Visible = True
End Sub
End Class
When the above code is executed and run using Start button available at the Microsoft
Visual Studio tool bar, it will show the following window −

Checking all the boxes −


Clicking the Submit button −

VB.Net - PictureBox Control


The PictureBox 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.

Methods of the PictureBox Control


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

Sr.No Method Name & Description


.

1
CancelAsync
Cancels an asynchronous image load.

2
Load
Displays an image in the picture box

3
LoadAsync
Loads image asynchronously.

4
ToString
Returns the string that represents the current picture box.

Events of the PictureBox Control


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

Sr.No Event & Description


.

1
CausesValidationChanged
Overrides the Control.CausesValidationChanged property.

2
Click
Occurs when the control is clicked.

3
Enter
Overrides the Control.Enter property.

4
FontChanged
Occurs when the value of the Font property changes.

5
ForeColorChanged
Occurs when the value of the ForeColor property changes.
6
KeyDown
Occurs when a key is pressed when the control has focus.

7
KeyPress
Occurs when a key is pressed when the control has focus.

8
KeyUp
Occurs when a key is released when the control has focus.

9
Leave
Occurs when input focus leaves the PictureBox.

10
LoadCompleted
Occurs when the asynchronous image-load operation is completed, been
canceled, or raised an exception.

11
LoadProgressChanged
Occurs when the progress of an asynchronous image-loading operation has
changed.

12
Resize
Occurs when the control is resized.

13
RightToLeftChanged
Occurs when the value of the RightToLeft property changes.

14
SizeChanged
Occurs when the Size property value changes.

15
SizeModeChanged
Occurs when SizeMode changes.
16
TabIndexChanged
Occurs when the value of the TabIndex property changes.

17
TabStopChanged
Occurs when the value of the TabStop property changes.

18
TextChanged
Occurs when the value of the Text property changes.

Example
In this example, let us put a picture box and a button control on the form. We set the
image property of the picture box to logo.png, as we used before. The Click event of the
button named Button1 is coded to stretch the image to a specified size −
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
' Set the caption bar text of the form.
Me.Text = "tutorialspoint.com"
End Sub

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


PictureBox1.ClientSize = New Size(300, 300)
PictureBox1.SizeMode = PictureBoxSizeMode.StretchImage
End Sub
End Class
Design View −
When the application is executed, it displays −

Clicking on the button results in −


VB.Net - ProgressBar Control
It represents a Windows progress bar 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.
Let's click on a ProgressBar control from the Toolbox and place it on the form.

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


.

1
AllowDrop
Overrides Control.AllowDrop.

2
BackgroundImage
Gets or sets the background image for the ProgressBar control.

3
BackgroundImageLayout
Gets or sets the layout of the background image of the progress bar.

4
CausesValidation
Gets or sets a value indicating whether the control, when it receives focus,
causes validation to be performed on any controls that require validation.

5
Font
Gets or sets the font of text in the ProgressBar.

6
ImeMode
Gets or sets the input method editor (IME) for the ProgressBar.

7
ImeModeBase
Gets or sets the IME mode of a control.

8
MarqueeAnimationSpeed
Gets or sets the time period, in milliseconds, that it takes the progress block to
scroll across the progress bar.

9
Maximum
Gets or sets the maximum value of the range of the control.v

10
Minimum
Gets or sets the minimum value of the range of the control.

11
Padding
Gets or sets the space between the edges of a ProgressBar control and its
contents.

12
RightToLeftLayout
Gets or sets a value indicating whether the ProgressBar and any text it
contains is displayed from right to left.

13
Step
Gets or sets the amount by which a call to the PerformStep method increases
the current position of the progress bar.

14
Style
Gets or sets the manner in which progress should be indicated on the progress
bar.

15
Value
Gets or sets the current position of the progress bar.v

Methods of the ProgressBar Control


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

Sr.No Method Name & Description


.

1
Increment
Increments the current position of the ProgressBar control by specified amount.

2
PerformStep
Increments the value by the specified step.

3
ResetText
Resets the Text property to its default value.

4
ToString
Returns a string that represents the progress bar control.

Events of the ProgressBar Control


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

Sr.No Event & Description


.

1
BackgroundImageChanged
Occurs when the value of the BackgroundImage property changes.

2
BackgroundImageLayoutChanged
Occurs when the value of the BackgroundImageLayout property changes.

3
CausesValidationChanged
Occurs when the value of the CausesValidation property changes.
4
Click
Occurs when the control is clicked.

5
DoubleClick
Occurs when the user double-clicks the control.

6
Enter
Occurs when focus enters the control.

7
FontChanged
Occurs when the value of the Font property changes.

8
ImeModeChanged
Occurs when the value of the ImeMode property changes.

9
KeyDown
Occurs when the user presses a key while the control has focus.

10
KeyPress
Occurs when the user presses a key while the control has focus.

11
KeyUp
Occurs when the user releases a key while the control has focus.

12
Leave
Occurs when focus leaves the ProgressBar control.

13
MouseClick
Occurs when the control is clicked by the mouse.

14
MouseDoubleClick
Occurs when the user double-clicks the control.

15
PaddingChanged
Occurs when the value of the Padding property changes.

16
Paint
Occurs when the ProgressBar is drawn.

17
RightToLeftLayoutChanged
Occurs when the RightToLeftLayout property changes.

18
TabStopChanged
Occurs when the TabStop property changes.

19
TextChanged
Occurs when the Text property changes.

Example
In this example, let us create a progress bar at runtime. Let's double click on the Form
and put the follow code in the opened window.
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) _
Handles MyBase.Load
'create two progress bars
Dim ProgressBar1 As ProgressBar
Dim ProgressBar2 As ProgressBar
ProgressBar1 = New ProgressBar()
ProgressBar2 = New ProgressBar()
'set position
ProgressBar1.Location = New Point(10, 10)
ProgressBar2.Location = New Point(10, 50)
'set values
ProgressBar1.Minimum = 0
ProgressBar1.Maximum = 200
ProgressBar1.Value = 130
ProgressBar2.Minimum = 0
ProgressBar2.Maximum = 100
ProgressBar2.Value = 40
'add the progress bar to the form
Me.Controls.Add(ProgressBar1)
Me.Controls.Add(ProgressBar2)
' Set the caption bar text of the form.
Me.Text = "tutorialspoint.com"
End Sub
End Class
When the above code is executed and run using Start button available at the Microsoft
Visual Studio tool bar, it will show the following window −

VB.Net - ScrollBar Control


The ScrollBar controls display vertical and horizontal scroll bars on the form. This is
used for navigating through large amount of information. There are two types of scroll
bar controls: HScrollBar for horizontal scroll bars and VScrollBar for vertical scroll
bars. These are used independently from each other.
Let's click on HScrollBar control and VScrollBar control from the Toolbox and place
them on the form.
Properties of the ScrollBar Control
The following are some of the commonly used properties of the ScrollBar control −

Sr.No Property & Description


.

1
AutoSize
Gets or sets a value indicating whether the ScrollBar is automatically resized to
fit its contents.

2
BackColor
Gets or sets the background color for the control.

3
ForeColor
Gets or sets the foreground color of the scroll bar control.

4
ImeMode
Gets or sets the Input Method Editor (IME) mode supported by this control.
5
LargeChange
Gets or sets a value to be added to or subtracted from the Value property when
the scroll box is moved a large distance.

6
Maximum
Gets or sets the upper limit of values of the scrollable range.

7
Minimum
Gets or sets the lower limit of values of the scrollable range.

8
SmallChange
Gets or sets the value to be added to or subtracted from the Value property
when the scroll box is moved a small distance.

9
Value
Gets or sets a numeric value that represents the current position of the scroll
box on the scroll bar control.

Methods of the ScrollBar Control


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

Sr.No Method Name & Description


.

1
OnClick
Generates the Click event.

2
Select
Activates the control.

Events of the ScrollBar Control


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

Sr.No Event & Description


.

1
Click
Occurs when the control is clicked.

2
DoubleClick
Occurs when the user double-clicks the control.

3
Scroll
Occurs when the control is moved.

4
ValueChanged
Occurs when the Value property changes, either by handling the Scroll event or
programmatically.

Example
In this example, let us create two scroll bars at runtime. Let's double click on the Form
and put the follow code in the opened window.
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) _
Handles MyBase.Load

'create two scroll bars


Dim hs As HScrollBar
Dim vs As VScrollBar
hs = New HScrollBar()
vs = New VScrollBar()

'set properties
hs.Location = New Point(10, 200)
hs.Size = New Size(175, 15)
hs.Value = 50
vs.Location = New Point(200, 30)
vs.Size = New Size(15, 175)
hs.Value = 50
'adding the scroll bars to the form
Me.Controls.Add(hs)
Me.Controls.Add(vs)
' Set the caption bar text of the form.
Me.Text = "tutorialspoint.com"
End Sub
End Class
When the above code is executed and run using Start button available at the Microsoft
Visual Studio tool bar, it will show the following window −

VB.Net - DateTimePicker Control


The DateTimePicker control allows selecting a date and time by editing the displayed
values in the control. If you click the arrow in the DateTimePicker control, it displays a
month calendar, like a combo box control. The user can make selection by clicking the
required date. The new selected value appears in the text box part of the control.
The MinDate and the MaxDate properties allow you to put limits on the date range.

Properties of the DateTimePicker Control


The following are some of the commonly used properties of the DateTimePicker control

Sr.No Property & Description


.

1
BackColor
Gets or sets a value indicating the background color of the DateTimePicker
control.

2
BackgroundImage
Gets or sets the background image for the control.

3
BackgroundImageLayout
Gets or sets the layout of the background image of the DateTimePicker control.

4
CalendarFont
Gets or sets the font style applied to the calendar.

5
CalendarForeColor
Gets or sets the foreground color of the calendar.

6
CalendarMonthBackground
Gets or sets the background color of the calendar month.

7
CalendarTitleBackColor
Gets or sets the background color of the calendar title.

8
CalendarTitleForeColor
Gets or sets the foreground color of the calendar title.

9
CalendarTrailingForeColor
Gets or sets the foreground color of the calendar trailing dates.

10
Checked
Gets or sets a value indicating whether the Value property has been set with a
valid date/time value and the displayed value is able to be updated.

11
CustomFormat
Gets or sets the custom date/time format string.

12
DropDownAlign
Gets or sets the alignment of the drop-down calendar on the DateTimePicker
control.

13
ForeColor
Gets or sets the foreground color of the DateTimePicker control.

14
Format
Gets or sets the format of the date and time displayed in the control.

15
MaxDate
Gets or sets the maximum date and time that can be selected in the control.

16
MaximumDateTime
Gets the maximum date value allowed for the DateTimePicker control.

17
MinDate
Gets or sets the minimum date and time that can be selected in the control.

18
MinimumDateTime
Gets the minimum date value allowed for the DateTimePicker control.

19
PreferredHeight
Gets the preferred height of the DateTimePicker control.

20
RightToLeftLayout
Gets or sets whether the contents of the DateTimePicker are laid out from right
to left.

21
ShowCheckBox
Gets or sets a value indicating whether a check box is displayed to the left of
the selected date.

22
ShowUpDown
Gets or sets a value indicating whether a spin button control (also known as an
up-down control) is used to adjust the date/time value.

23
Text
Gets or sets the text associated with this control.

24
Value
Gets or sets the date/time value assigned to the control.

Methods of the DateTimePicker Control


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

Sr.No Method Name & Description


.

1
ToString
Returns the string representing the control.

Events of the DateTimePicker Control


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

Sr.No Event & Description


.

1
BackColorChanged
Occurs when the value of the BackColor property changes.

2
BackgroundImageChanged
Occurs when the value of the BackgroundImage property changes.

3
BackgroundImageLayoutChanged
Occurs when the value of the BackgroundImageLayout property changes.

4
Click
Occurs when the control is clicked.
5
CloseUp
Occurs when the drop-down calendar is dismissed and disappears.

6
DoubleClick
Occurs when the control is double-clicked.

7
DragDrop
Occurs when a drag-and-drop operation is completed.

8
ForeColorChanged
Occurs when the value of the ForeColor property changes.

9
FormatChanged
Occurs when the Format property value has changed.

10
MouseClick
Occurs when the control is clicked with the mouse.

11
MouseDoubleClick
Occurs when the control is double-clicked with the mouse.

12
PaddingChanged
Occurs when the value of the Padding property changes.

13
Paint
Occurs when the control is redrawn.

14
RightToLeftLayoutChanged
Occurs when the RightToLeftLayout property changes.

15
TextChanged
Occurs when the value of the Text property changes.

16
ValueChanged
Occurs when the Value property changes.

Example
In this example, let us create a small application for calculating days of leave. Let us
add two DateTimePicker controls on the form, where the user will enter the date of
going on leave and the date of joining. Let us keep a button control for performing the
calculation and appropriate label controls for displaying information.
The form in design view −

Add the following code in the code editor window −


Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
' Set the caption bar text of the form.
Me.Text = "tutorialspoint.com"
End Sub

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


Dim d1 As DateTime = DateTimePicker1.Value
Dim d2 As DateTime = DateTimePicker2.Value
Dim result As TimeSpan = d1.Subtract(d2)
Dim days As Integer = result.TotalDays
Label3.Text = days
End Sub
End Class
When the above code is executed and run using Start button available at the Microsoft
Visual Studio tool bar, it will show the following window −

Select two dates and click on the button for leave calculation −

VB.Net - TreeView 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


.

1
BackColor
Gets or sets the background color for the control.

2
BackgroundImage
Gets or set the background image for the TreeView control.

3
BackgroundImageLayout
Gets or sets the layout of the background image for the TreeView control.

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

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

6
DataBindings
Gets the data bindings for the control.

7
Font
Gets or sets the font of the text displayed by the control.

8
FontHeight
Gets or sets the height of the font of the control.

9
ForeColor
The current foreground color for this control, which is the color the control uses
to draw its text.

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

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

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

13
RightToLeftLayout
Gets or sets a value that indicates whether the TreeView should be laid out
from right-to-left.

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

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

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

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

18
ShowLines
Gets or sets a value indicating whether lines are drawn between tree nodes in
the tree view control.

19
ShowNodeToolTips
Gets or sets a value indicating ToolTips are shown when the mouse pointer
hovers over a TreeNode.

20
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.

21
ShowRootLines
Gets or sets a value indicating whether lines are drawn between the tree nodes
that are at the root of the tree view.

22
Sorted
Gets or sets a value indicating whether the tree nodes in the tree view are
sorted.
23
StateImageList
Gets or sets the image list that is used to indicate the state of the TreeView and
its nodes.

24
Text
Gets or sets the text of the TreeView.

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

26
TreeViewNodeSorter
Gets or sets the implementation of IComparer to perform a custom sort of the
TreeView nodes.

27
VisibleCount
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


.

1
CollapseAll
Collapses all the nodes including all child nodes in the tree view control.

2
ExpandAll
Expands all the nodes.

3
GetNodeAt
Gets the node at the specified location.
4
GetNodeCount
Gets the number of tree nodes.

5
Sort
Sorts all the items in the tree view control.

6
ToString
Returns a string containing the name of the control.

Events of the TreeView Control


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

Sr.No Event & Description


.

1
AfterCheck
Occurs after the tree node check box is checked.

2
AfterCollapse
Occurs after the tree node is collapsed.

3
AfterExpand
Occurs after the tree node is expanded.

4
AfterSelect
Occurs after the tree node is selected.

5
BeforeCheck
Occurs before the tree node check box is checked.

6
BeforeCollapse
Occurs before the tree node is collapsed.

7
BeforeExpand
Occurs before the tree node is expanded.

8
BeforeLabelEdit
Occurs before the tree node label text is edited.

9
BeforeSelect
Occurs before the tree node is selected.

10
ItemDrag
Occurs when the user begins dragging a node.

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

12
NodeMouseDoubleClick
Occurs when the user double-clicks a TreeNode with the mouse.

13
NodeMouseHover
Occurs when the mouse hovers over a TreeNode.

14
PaddingChanged
Occurs when the value of the Padding property changes.

15
Paint
Occurs when the TreeView is drawn.

16
RightToLeftLayoutChanged
Occurs when the value of the RightToLeftLayout property changes.
17
TextChanged
Occurs when the Text property changes.

The TreeNode Class


The TreeNode class represents a node of a TreeView. Each node in a TreeView control
is an object of the TreeNode class. To be able to use a TreeView control we need to
have a look at some commonly used properties and methods of the TreeNode class.

Properties of the TreeNode Class


The following are some of the commonly used properties of the TreeNode class −

Sr.No Property & Description


.

1
BackColor
Gets or sets the background color of the tree node.

2
Checked
Gets or sets a value indicating whether the tree node is in a checked state.

3
ContextMenu
Gets the shortcut menu that is associated with this tree node.

4
ContextMenuStrip
Gets or sets the shortcut menu associated with this tree node.

5
FirstNode
Gets the first child tree node in the tree node collection.

6
FullPath
Gets the path from the root tree node to the current tree node.
7
Index
Gets the position of the tree node in the tree node collection.

8
IsEditing
Gets a value indicating whether the tree node is in an editable state.

9
IsExpanded
Gets a value indicating whether the tree node is in the expanded state.

10
IsSelected
Gets a value indicating whether the tree node is in the selected state.

11
IsVisible
Gets a value indicating whether the tree node is visible or partially visible.

12
LastNode
Gets the last child tree node.

13
Level
Gets the zero-based depth of the tree node in the TreeView control.

14
Name
Gets or sets the name of the tree node.

15
NextNode
Gets the next sibling tree node.

16
Nodes
Gets the collection of TreeNode objects assigned to the current tree node.

17
Parent
Gets the parent tree node of the current tree node.

18
PrevNode
Gets the previous sibling tree node.

19
PrevVisibleNode
Gets the previous visible tree node.

20
Tag
Gets or sets the object that contains data about the tree node.

21
Text
Gets or sets the text displayed in the label of the tree node.

22
ToolTipText
Gets or sets the text that appears when the mouse pointer hovers over a
TreeNode.

23
TreeView
Gets the parent tree view that the tree node is assigned to.

Methods of the TreeNode Class


The following are some of the commonly used methods of the TreeNode class −

Sr.No Method Name & Description


.

1
Collapse
Collapses the tree node.

2
Expand
Expands the tree node.

3
ExpandAll
Expands all the child tree nodes.

4
GetNodeCount
Returns the number of child tree nodes.

5
Remove
Removes the current tree node from the tree view control.

6
Toggle
Toggles the tree node to either the expanded or collapsed state.

7
ToString
Returns a string that represents the current object.

Example
In this example, let us create a tree view at runtime. Let's double click on the Form and
put the follow code in the opened window.
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
'create a new TreeView
Dim TreeView1 As TreeView
TreeView1 = New TreeView()
TreeView1.Location = New Point(10, 10)
TreeView1.Size = New Size(150, 150)

Me.Controls.Add(TreeView1)
TreeView1.Nodes.Clear()
'Creating the root node
Dim root = New TreeNode("Application")
TreeView1.Nodes.Add(root)
TreeView1.Nodes(0).Nodes.Add(New TreeNode("Project 1"))
'Creating child nodes under the first child
For loopindex As Integer = 1 To 4
TreeView1.Nodes(0).Nodes(0).Nodes.Add(New _
TreeNode("Sub Project" & Str(loopindex)))
Next loopindex
' creating child nodes under the root
TreeView1.Nodes(0).Nodes.Add(New TreeNode("Project 6"))
'creating child nodes under the created child node

For loopindex As Integer = 1 To 3


TreeView1.Nodes(0).Nodes(1).Nodes.Add(New _
TreeNode("Project File" & Str(loopindex)))
Next loopindex
' Set the caption bar text of the form.
Me.Text = "tutorialspoint.com"
End Sub
End Class
When the above code is executed and run using Start button available at the Microsoft
Visual Studio tool bar, it will show the following window −

You can expand the nodes to see the child nodes −


VB.Net - ListView Control
The ListView control is used to display a list of items. Along with the TreeView control, it
allows you to create a Windows Explorer like interface.
Let's click on a ListView control from the Toolbox and place it on the form.

The ListView control displays a list of items along with icons. The Item property of the
ListView control allows you to add and remove items from it. The SelectedItem property
contains a collection of the selected items. The MultiSelect property allows you to set
select more than one item in the list view. The CheckBoxes property allows you to set
check boxes next to the items.
Properties of the ListView Control
The following are some of the commonly used properties of the ListView control −

Sr.No Property & Description

1
Alignment
Gets or sets the alignment of items in the control.

2
AutoArrange
Gets or sets whether icons are automatically kept arranged.

3
BackColor
Gets or sets the background color.

4
CheckBoxes
Gets or sets a value indicating whether a check box appears next to each item
in the control.

5
CheckedIndices
Gets the indexes of the currently checked items in the control.

6
CheckedItems
Gets the currently checked items in the control.

7
Columns
Gets the collection of all column headers that appear in the control.

8
GridLines
Gets or sets a value indicating whether grid lines appear between the rows and
columns containing the items and subitems in the control.

9
HeaderStyle
Gets or sets the column header style.

10
HideSelection
Gets or sets a value indicating whether the selected item in the control remains
highlighted when the control loses focus.

11
HotTracking
Gets or sets a value indicating whether the text of an item or subitem has the
appearance of a hyperlink when the mouse pointer passes over it.

12
HoverSelection
Gets or sets a value indicating whether an item is automatically selected when
the mouse pointer remains over the item for a few seconds.

13
InsertionMark
Gets an object used to indicate the expected drop location when an item is
dragged within a ListView control.

14
Items
Gets a collection containing all items in the control.

15
LabelWrap
Gets or sets a value indicating whether item labels wrap when items are
displayed in the control as icons.

16
LargeImageList
Gets or sets the ImageList to use when displaying items as large icons in the
control.

17
MultiSelect
Gets or sets a value indicating whether multiple items can be selected.

18
RightToLeftLayout
Gets or sets a value indicating whether the control is laid out from right to left.

19
Scrollable
Gets or sets a value indicating whether a scroll bar is added to the control when
there is not enough room to display all items.

20
SelectedIndices
Gets the indexes of the selected items in the control.

21
SelectedItems
Gets the items that are selected in the control.

22
ShowGroups
Gets or sets a value indicating whether items are displayed in groups.

23
ShowItemToolTips
Gets or sets a value indicating whether ToolTips are shown for the ListViewItem
objects contained in theListView.

24
SmallImageList
Gets or sets the ImageList to use when displaying items as small icons in the
control.

25
Sorting
Gets or sets the sort order for items in the control.

26
StateImageList
Gets or sets the ImageList associated with application-defined states in the
control.

27
TopItem
Gets or sets the first visible item in the control.

28
View
Gets or sets how items are displayed in the control. This property has the
following values:

 LargeIcon − displays large items with a large 32 x 32 pixels icon.


 SmallIcon − displays items with a small 16 x 16 pixels icon
 List − displays small icons always in one column
 Details − displays items in multiple columns with column headers and
fields
 Tile − displays items as full-size icons with item labels and sub-item
information.

29
VirtualListSize
Gets or sets the number of ListViewItem objects contained in the list when in
virtual mode.

30
VirtualMode
Gets or sets a value indicating whether you have provided your own data-
management operations for the ListView control.

Methods of the ListView Control


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

Sr.No Method Name & Description


.

1
Clear
Removes all items from the ListView control.

1
ToString
Returns a string containing the string representation of the control.
Events of the ListView Control
The following are some of the commonly used events of the ListView control −

Sr.No Event & Description


.

1
ColumnClick
Occurs when a column header is clicked.

2
ItemCheck
Occurs when an item in the control is checked or unchecked.

3
SelectedIndexChanged
Occurs when the selected index is changed.

4
TextChanged
Occurs when the Text property is changed.

Example
In this example, let us create a list view at runtime. Let's double click on the Form and
put the follow code in the opened window.
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
'create a new ListView
Dim ListView1 As ListView
ListView1 = New ListView()
ListView1.Location = New Point(10, 10)
ListView1.Size = New Size(150, 150)

Me.Controls.Add(ListView1)
'Creating the list items
Dim ListItem1 As ListViewItem
ListItem1 = ListView1.Items.Add("Item 1")

Dim ListItem2 As ListViewItem


ListItem2 = ListView1.Items.Add("Item 2")
Dim ListItem3 As ListViewItem
ListItem3 = ListView1.Items.Add("Item 3")

Dim ListItem4 As ListViewItem


ListItem4 = ListView1.Items.Add("Item 4")
'set the view property

ListView1.View = View.SmallIcon
' Set the caption bar text of the form.
Me.Text = "tutorialspoint.com"
End Sub
End Class
When the above code is executed and run using Start button available at the Microsoft
Visual Studio tool bar, it will show the following window −

You might also like