Tutorial 1: An Introduction to Visual Basic .NET 1
An Introduction to Visual Basic .NET
Tutorial 1: An Introduction to Visual Basic .NET 2
Creating a Windows-Based Application
in Visual Basic .NET
Lesson A
Tutorial 1: An Introduction to Visual Basic .NET 3
Lesson A Objectives
After completing this lesson, you will be able to:
Start and customize Visual Studio .NET
Create a Visual Studio .NET solution
Add a Visual Basic .NET project to a solution
Set the properties of an object
Save a solution, project, and form
Close a solution
Open an existing solution
Tutorial 1: An Introduction to Visual Basic .NET 4
Starting and Customizing
Visual Studio .NET
Visual Studio .NET is Microsoft’s newest integrated
development environment (IDE)
Includes programming languages such as Visual
Basic .NET, C++ .NET, and C# .NET
A Windows-based application has a Windows user
interface and runs on a desktop computer
A user interface is what you see and interact with when
using an application
A Web-based application, on the other hand, has a Web
user interface and runs on a server
Tutorial 1: An Introduction to Visual Basic .NET 5
The Visual Studio .NET Start Page
Links
Tutorial 1: An Introduction to Visual Basic .NET 6
Visual Studio .NET
Recent Projects
Solution
Explorer
Dynamic
Help
Toolbox
Tutorial 1: An Introduction to Visual Basic .NET 7
Starting a New Project
Installed .NET
Products
Type of
Project
Name and Location
Of Project
Name of
Project
Tutorial 1: An Introduction to Visual Basic .NET 8
Purpose of the Links
Included on the Start Page
Link Purpose
Get Started Create new projects and open existing projects
What’s New Access information about the new features in Visual Studio .NET
and check for Visual Studio .NET updates
Online Community Contact fellow developers online
Headlines View links to the latest news from the MSDN Online Library,
including information on seminars, trade shows, and
conferences, as well as training opportunities offered by
Microsoft
Search Online Search the MSDN Online Library
Downloads Access the latest product updates and sample code available for
download
XML Web Services Search for XML Web Services to include in your applications,
and publish your own XML Web services
Web Hosting Post Web applications, for a fee, on servers provided by third-
party Internet Service Providers
My Profile Customize various program settings in the IDE
Tutorial 1: An Introduction to Visual Basic .NET 9
Visual Basic .NET
Project
information
Properties
window
Toolbox
(auto-
hidden)
Windows
Form object
Tutorial 1: An Introduction to Visual Basic .NET 10
Working with Controls
Lesson B Objectives
After completing this lesson, you will be able to:
Add a control to a form
Set the properties of a label, picture box, and button control
Select multiple controls
Center controls on the form
Set the properties of a project
Start and end an application
Enter code in the Code Editor window
Terminate an application using the Me.Close method
Tutorial 1: An Introduction to Visual Basic .NET 11
Working With Controls
Toolbox Item Description
Data Components to access data and data
sources
Components Components to perform special tasks
Clipboard Ring Stores items that you have copied
General Can be used to store code snippets
Windows Forms Objects used to create user interface
Tutorial 1: An Introduction to Visual Basic .NET 12
The Toolbox Window
The Toolbox window, or toolbox, contains the tools and
other components you use when designing a user interface
The contents of the toolbox vary depending on the
designer in use
Tutorial 1: An Introduction to Visual Basic .NET 13
The Windows Form Tab
The Windows Form tab
Contains the tools you use when designing
your user interface
Contains 47 basic tools
However, you can add new tools or delete existing
tools by right-clicking the tab and then clicking
Customize Toolbox on the context menu
By default, the tools on the Windows Form tab are listed in
order by their estimated frequency of use, with the most
used tools listed first
Tutorial 1: An Introduction to Visual Basic .NET 14
Using the Label Tool
The tools in the toolbox allow you to create objects, called
controls, that can be displayed on a form
You use the Label tool to create a label control
The purpose of a label control is to display text that the
user is not allowed to edit while the application is running
Assigning meaningful names to the controls on a form will
help you keep track of the various controls in the user
interface
Tutorial 1: An Introduction to Visual Basic .NET 15
Using the Label Tool
Used to display data that users cannot change
Property Description
Name Identifies the object in code
Text Displayed information
AutoSize Determines if the object resizes
itself to display all Text
Location Sets the X and Y coordinates for
where label is displayed
Font Characteristics of the displayed
Text
Tutorial 1: An Introduction to Visual Basic .NET 16
Key Form Properties
Property Description
Name Used to refer to the object
Text Caption displayed in the title bar
StartPosition Position of window on screen
BackgroundImage Image displayed on the form
Size Width and Height of window
Location Left and Top position of window
Tutorial 1: An Introduction to Visual Basic .NET 17
Changing the Property for
More Than One Control at a Time
You can use the Font property to change the appearance of
many of the objects in your user interface
The Font property allows you to change the type of font
used to display the text in the object, as well as the style
and size of the font
Tutorial 1: An Introduction to Visual Basic .NET 18
Fonts
A font is the general shape of the characters in the text
Courier, Tahoma, and Microsoft Sans Serif
Font styles include regular, bold, and italic
Tutorial 1: An Introduction to Visual Basic .NET 19
Changing the Property for
More Than One Control at a Time
The numbers 8, 10, and 18 are examples of font sizes,
which typically are measured in points, with one point
equaling 1/72 of an inch
One reason for changing a font is to bring attention to a
specific part of the screen
You can change the font size for both controls at the same
time by clicking one control and then pressing and holding
down the Control key as you click the other control in the
form
Tutorial 1: An Introduction to Visual Basic .NET 20
Changing the Property for
More Than One Control at a Time
You can use the Control+Click method to
select as many controls as you want
To cancel the selection of one of the selected
controls, press and hold down the Control
key as you click the control
To cancel the selection of all of the selected
controls, release the Control key, then click
the form or an unselected control on the form
Tutorial 1: An Introduction to Visual Basic .NET 21
Using the Format Menu
The Format menu provides options that allow you to
manipulate the controls in the user interface
The Align option allows you to align two or more controls
by their left, right, top, or bottom borders
You can use the Make Same Size option to make two or
more controls the same width or height, or both width and
height
The Format menu also has a Center in Form option that
centers one or more controls either horizontally or
vertically on the form
Tutorial 1: An Introduction to Visual Basic .NET 22
Using the PictureBox Tool
You can include a logo by displaying the
logo in a picture box control, which you
create using the PictureBox tool
Tutorial 1: An Introduction to Visual Basic .NET 23
Using the Button Tool
Every Windows application should give the user a way to
exit the program
Most Windows applications provide either an Exit
option on a File menu or an Exit button for this
purpose
In Windows applications, a button control performs an
immediate action when clicked
You create a button using the Button tool in the toolbox
Tutorial 1: An Introduction to Visual Basic .NET 24
Starting and Ending an Application
You can start an application by
Clicking Debug on the menu bar, and then clicking Start
Or you can simply press the F5 key on your keyboard
When you start an application, Visual Studio .NET
automatically creates a file that can be run outside of the
Visual Studio .NET IDE
The file, referred to as an executable file, has the same
name as the project, but with an .exe filename extension
Tutorial 1: An Introduction to Visual Basic .NET 25
Writing Visual Basic .NET Code
Actions—such as clicking, double-clicking, and scrolling—
are called events
The set of Visual Basic .NET instructions, or code, that tells
an object how to respond to an event is called an event
procedure
A class definition is simply a block of code that specifies
(or defines) the attributes and behaviors of an object
When you start the application, Visual Basic .NET uses the
class definition to create the object