Code for Visual Basic Programmers

abashedwhimsicalSoftware and s/w Development

Nov 2, 2013 (3 years and 7 months ago)

733 views

Code for Visual Basic Programmers

There are many sources of code within the Visual Basic documentation set. This topic helps you get started in
locating that code. Note that some of this code is contained within topics that provide further explanation or
i
nstructions on how to perform a task, whereas some is contained in special topics devoted only to displaying a
code example.

Code in the Visual Basic Documentation

The following topics highlight useful code samples, by feature, within the Visual Basic doc
umentation.

Code for Windows Forms Applications


Lists code examples in the "Creating Windows Applications" section of the documentation.

Code for Windows Forms Controls


Lists code examples in the "Windows Forms Controls" section of the documentation.

Code for Data Access


Lis
ts code examples in the "Accessing Data" section of the documentation.

Code for Web Applications


Lists code examples in the "Creating Web Applications and Services" section of t
he documentation.

Code for Web Forms Controls


Lists code examples in the "ASP.NET Server Controls" section of the documentation

Code for Component Programming


Lists code examples in the "Programming with Components" section of the documentation.

Other Sources for Sample Code

You can also find sample code in the following locations:

Visual Basic Code Example Topics


Lists quickstart
-
like code examples that help you perform common tasks in Visual Basic .NET.

Visual Basic Language Tour


Provides links to topics that contain code showing how to use basic language features, such as threading,
inheritance, and file IO.

Visual Basi
c Sample Applications


Lists compiled sample applications available to you in the documentation set.

Walkthroughs in Visual Basic and Visual C#


Lists tutorial topics that provi
de step
-
by
-
step instructions on the process of creating applications and
learning to use specific features.

Visual Basic QuickStarts and Other Samples


Lists samples available to

you when you install the .NET Framework SDK.

.NET Framework Reference Information


Provides links to reference topics, some of which code examples of how to use classes and thei
r members
in.

Additional Resources for Visual Basic Programmers

The following Web sites and newsgroups can help you find answers to common problems.

Microsoft Resources

On the Web

http://support.microsoft.com


Provides access to Knowledge Base (KB) articles, downloads and updates, support Webcasts, and other
services.

http://www.gotdotnet.com/team/vb


Contains articles, samples,

and other information of interest to Visual Basic .NET developers.

http://msdn.microsoft.com/vbasic


Provides code samples, upgrade information, and technical content.

http://msdn.microsoft.com/newsgroups


Provides a way to connect as a community with experts from around the world.

http://www.asp.net


Provides articles, dem
onstrations, tool previews, and other information for Web development in Visual
Basic.

In Newsgroups

microsoft.public.dotnet.languages.vb


Provides a forum for questions and general discussion of

Visual Basic .NET.

microsoft.public.dotnet.languages.vb.upgrade


Provides a forum for questions and issues on upgrading to Visual Basic .NET.

microsoft.public.vsnet.general


Provides a forum for questions and issues on Visual Studio .NET.

microsoft.public.vsnet.ide


Provides a forum for questions about working in the Visual Studio env
ironment.

microsoft.public.vsnet.documentation


Provides a forum for questions and issues on the Visual Basic .NET documentation.

Third
-
Party Resources

MSDN's Web site provides information on cu
rrent third
-
party sites and newsgroups of interest. For the most current
list of resources available, see the MSDN Community Web site
(http://msdn.microsoft.com/vbasic/community)
.

On th
e Web

Universal Thread

(http://www.universalthread.com/net)

Provides the latest news, interviews, and hints on Visual Basic .NET.

DevX Visual Basic Zone

(http://ww
w.devx.com/vb)

Provides in
-
depth technical articles for today's Visual Basic developer moving to Visual Basic .NET.

VbCity

(http://www.devcity.net/net)

Provides access to more than 5,000 Microsoft Visual Basic

and Active Server Pages (ASP) articles, source
code, tutorials, and user
-
submitted content when you join vbCity.com.

Newsgroups

vb.dotnet.technical

(ht
tp://news.devx.com)

Provides a forum for discussion of new features in Visual Basic .NET in the DevX forums.

Getting Started with Visual Basic

This section of the documentation helps you get started with Visual Basic application development.


In This S
ection

What's New in Visual Basic


Covers new features for Visual Basic.

Visual Basic Editions


Describes the feat
ures that come with Visual Studio and the .NET Framework.

Visual Basic Language Walkthroughs


Provides a list of Help pages that demonstrate aspects of the Visual Basic language.

Additional Resources for Visual Basic Programmers


Provides a list of Web sites and newsgroups that can help you find answers to common problems.

How Do I in Visual Basic


Provides categorized pages of links to "how
-
to" Help pages on important programming subjects.


Related Sections

Visual Basic Guided
Tour


Provides a series of sequential lessons that introduce you to the basics of programming in Visual Basic.


Visual Basic Guided Tour

Whether you are new to Visual Basic, or perhaps new to computer programming, this is the place to start. The
Visual
Basic Guided Tour is a series of sequential lessons that introduce you to the basics of programming in Visual
Basic.


In This Section

Getting Started with Visual Basic Express


A seri
es of topics introducing Visual Basic Express and the Visual Basic development environment.

Creating Your First Visual Basic Program


In this section, you will see how easy it is to crea
te a program for viewing Web pages.

Introduction to the Visual Basic Express IDE


A series of topics introducing the Visual Basic integrated development environment.

Introduction to the Visual Basic Programming Language


In this section, you will learn the basics of the Visual Basic language.

Creating
the Visual Look of Your Program: Introduction to Windows Forms


In this section, you will learn how to use forms and controls to create a user interface.

Creating the Visual Look of Your

Program: Introduction to Windows Presentation Foundation


In this section, you will learn how to create a user interface for a Windows Presentation Foundation
application.

What Went Wro
ng? Finding and Fixing Errors Through Debugging


In this section, you will learn how to use the debugging tools in Visual Basic.

Managing Your Records: Using Data in Your Program


In th
is section, you will learn about how to work with databases.

Using the File System: Writing to and Reading from Files


In this section, you will learn how to write to and read from text
files by using the
My.Computer.FileSystem Object
.

Programming with Objects: Using Classes


In this section, you will

learn the basics of object
-
oriented programming.

Visible Objects: Creating Your First User Control


In this section, you will learn how to create your own reusable control.

Drawing Pictures: Using Graphics


In this section, you will learn about the graphics capabilities of Visual Basic.

Distributing a

Program


In this section, you will learn how to share your programs with others.

Moving Forward: Where Do I Go from Here?


A series of topics linking to additional resources for master
ing Visual Basic.

Getting Started with Visual Basic Express

Whether you are a Visual Basic 6.0 veteran who wants to upgrade, an experienced programmer interested in
learning Visual Basic for the first time, or even someone new to computer programming, Visu
al Basic 2008 Express
Edition has been designed for you. More than just a scaled
-
down version of Visual Basic, Visual Basic Express was
built expressly to make programming easier

than ever. It also makes programming more fun.

The Visual Basic Guided Tour i
ncludes a series of lessons that will help you quickly learn both the Visual Basic
language and the Visual Basic Express tools. Before you start, you might want to review some of the topics in this
section to learn about the capabilities of Visual Basic Ex
press. If you are new to programming, you can start
learning with
Creating Your First Visual Basic Program
, and then come back to these topics later.


In This Section

What's New in Visual Basic Express


Describes the new features that are available in Visual Basic Express. This includes Windows Presentation
Foundation (WPF), Language
-
Integrated Query (LINQ), and WCF S
ervices consumption.

Introduction to Visual Basic Express


More than just a learning tool, Visual Basic Express

provides a full
-
fledged development environment for
first
-
time programmers

and hobbyists who are interested in building Windows Forms applications, console
applications, and class libraries.

How Do I in Visual Basic Express


Provides links to topics that descr
ibe the most common programming tasks in Visual Basic Express.

Overview of Developing Applications with Visual Basic Express


Provides an overview of Visual Basic Express; a program for
creating applications by using the Visual Basic
language.


Using LINQ in Visual Basic Express


Gives an overview of Language
-
Integrated Query (LINQ) and provides links to topics that des
cribe LINQ in
more detail.

How to: Work with an Existing Application


If you are already familiar with Visual Basic and have an application that you want to work with, opening
an existin
g application is easy.

Samples and Resources: Getting Started Quickly


Visual Basic Express

provides sample applications and other resources to help you start writing programs
immediatel
y.


Project Types in Visual Basic Express


Visual Basic Express

enables you to create several types of applications. This includes

Windows Forms
applications, console applications, and c
lass libraries.

Troubleshooting Visual Basic Express


Although Visual Basic Express makes programming easy, you might have to

resolve problems that occur
as you create your applications.


Related Sections

Visual Basic Guided Tour


The Visual Basic Guided Tour is a series of sequential lessons that will introduce you to the basics of
programming in Visual Basic.

Creating Your First Visual Basic Program


The best way to learn programming with Visual Basic is to actually create a program.

Moving Forward: Where Do I Go from Here?


Now that you have completed the lessons in the
Visual Basic Guided Tour
, it's time to move on.

Help for Visual Basic 6.0 Users


Your knowledge of Visual Basic 6.0 will quickly help you become productive using Visual Basic 2008.

What's New for Visual Basic
6.0 Users


If you are an experienced user of Visual Basic 6.0, you will find a multitude of features in Visual Basic
2008 that are new or significantly improved. This makes development with Visual Basic easier and more
powerful than with any earlier versi
on.

Introduction to Visual Basic Express

If you can imagine a computer program, you can probably create it with Visual Basic Express. From a simple
program that displays a message, to a full
-
fledged application that accesses a database or a Web service, Vi
sual
Basic Express gives you the tools you need.

Visual Basic Express

provides a fully functional development environment for first
-
time programmers and hobbyists
who are interested in building Windows Forms applications, Windows Presentation Foundation cl
ient applications,
Windows Presentation Foundation browser applications, console applications, and class libraries. Visual Basic
Express

is the ideal choice for first
-
time developers who are interested in learning how to program in the Visual
Basic languag
e.


What Is Visual Basic Express?

Visual Basic Express is a version of Visual Basic that is easy to learn and available as a free download on the


MSDN

Web site. It is a fully functional devel
opment tool for programmers who do not need the full version of Visual
Basic. It is also a tool for learning to program in Visual Basic. But Visual Basic Express is more than just a subset of
Visual Basic: It includes many features that make Visual Basic p
rogramming easier than ever.

The best way to learn what you can do with Visual Basic Express is to work through the lessons in the
Visual Basic
Guided Tour
. When you finish, you will be
familiar with Visual Basic tools and concepts

and ready to start writing
your own programs.


Who Should Use Visual Basic Express?

Visual Basic Express is a powerful tool that can create fully functional applications and components that can be
shared with

others. However, it is not intended for professional developers or for programmers who work in a team
environment. Other versions of Visual Basic provide features that meet the advanced needs of professional and
team development.

If you have to write appl
ications that connect to a networked database, interact with Microsoft Office, support
mobile devices or 64
-
bit operating systems, or require remote debugging, you will need a more advanced version
of Visual Basic.

Note:

Visual Basic Express does not sup
port development of Web applications; if you want to do Web
development, you can download Visual Web Developer Express.


Getting Help

The Help files that are included with Visual Basic Express are a subset of the MSDN Library for Visual Studio
Express E
ditions, which is in turn a subset of the full MSDN Library. If you are connected to the Internet, you can
access any Help topic in the full library. If you do not have online access or you chose not to install the MSDN
Library for Visual Studio Express Ed
itions, some Help topics may not be available. For more information, see
Troubleshooting Visual Basic Express
.

Project Types in Visual Basic Express

Visual Basic Express enables you to c
reate several types of applications. This includes Windows Forms applications,
Windows Presentation Foundation applications, console applications, and class libraries. Each application that you
create is contained in its own project, and project templates
are provided to help you get started.

When you create a new project, icons in the
New Project

dialog box and
Add Project

dialog box represent the
available project types and their templates. The following project templates are available when you open a new

project in Visual Basic Express.


Project Types

Project template

Used to create

Windows
Application
Template

Used to create Windows
-
based applications that run locally on users' computers.
You can build anything from a simple single
-
window tool like Wi
ndows Calculator to
a complete application that has multiple windows and advanced capabilities.

Class Library
Template

Used to create reusable classes or components that can be shared with multiple
projects.

Console
Application
Template

Used to create c
ommand
-
line applications, programs that run from a Windows
command prompt and have no visual interface.

WPF
Application

Used to create stand
-
alone Windows Presentation Foundation applications.

WPF Browser
Application

Used to create browser
-
hosted Windows

Presentation Foundation applications.

Note:

Although there is no project template for Windows control libraries, you can still create your own
controls by using the
Class Library

template. For more information, see
Visible Objects: Creating Your
First User Control
.

Overview of Developing Applications with Visual Basic Express

This topic provides an overview of Visual Basic Express, a program for creating applications that use the Vis
ual
Basic language. Just as a program like Microsoft Outlook provides a variety of tools for working with e
-
mail,

Visual
Basic Express is a toolkit for accomplishing a wide variety of programming tasks.

Tip:

If you are new to programming, you may want to

complete the Visual Basic Guided Tour, a set of
lessons designed to teach you the basics, and then return to this topic. To start the tour, see
Creating
Your First Visual Basic Program
.


The Development Process

Visual Basic Express makes developing an application easy

most of the time the process consists of the following
steps:



Create a project.

A project contains all the files necessary for your application, and it stores informatio
n
about your application. For more information, see
Step 1: Create a Project in Visual Basic
. Sometimes an
application will contain more than one project, for example, a
Windows Applicat
ion

project and one or
more
Class Library

projects. Such an application is called a
solution
, which is just another name for a
group of projects.



Design the user interface.

You do this by dragging various controls, such as button and text boxes,
onto a des
ign surface known as a
form
. You can then set properties that define the appearance and
behavior of the form and its controls.

Note:

For applications that have no user interface, such as class libraries or console applications, this step is
not required
.



Write the code.

Next you will have to write the Visual Basic

code that defines how

your application will
behave and how it will

interact with the user. Visual Basic Express makes it easy to write code, providing
features like IntelliSense, auto
-
completi
on, and code snippets. For more information, see
Step 4: Add
Visual Basic Code
.



Test the code.

You will always want to test your application to make sure that it behaves the way that
you

expect it to. This process is known as
debugging.
Visual Basic Express has debugging tools that make
it easy to find and fix errors in your code interactively. For more information, see
Step 5: Run and Test
Your Program
.



Distribute the application.

Once your application is complete, you can install the resulting program on
your computer or distribute it and share it with others. Visual Basic Express uses a new technology known
as ClickOn
ce

Publishing that enables you to easily deploy an application by using a wizard, and to
automatically provide updated versions of the application if you later make changes. For more
information, see
Distributing a Program
.


Getting Around

At first glance, the user interface for Visual Basic Express, also known as the
Integrated Development Environment

or
IDE
, may seem unfamiliar, but after you learn your way around, you will find that
it is easy to use. The following
sections describe parts of the IDE that you will use the most. You can also learn more about the IDE in
Introduction
to the Visual Basic Express IDE
.

On
Startup

When you first open Visual Basic Express, you see that most of the IDE is filled with the
Start Page

window. The
Start Page

contains a clickable list of your recent projects, a
Getting Started

area with links to important Help
topics, and a list of

links to online articles and other resources. If you are connected to the Internet, this list will be
updated regularly.

On the right
-
hand side of the IDE, you see the
Solution Explorer

window, as shown in the following illustration. It
is initially blank
, but this is where information about your project, or groups of projects known as solutions, will be
displayed. For more information, see
Exploring Your Solution: Using Solution Explorer
.

Figure 1: Solution Explorer



On the left
-
hand side of the IDE, you see a vertical tab marked
Toolbox
. It is also initially blank, but as you work
it will be filled up with items that can be used for the task you are currently working on. For more info
rmation, see
Rummaging Through the Toolbox
.

Across the top of the IDE are a menu bar and a toolbar. The available menus and toolbar buttons change based on
your current task

take some t
ime to explore and see what choices are available. You can also customize the
menus and toolbar to match your personal preferences. You customize the toolbar by clicking the
Tools

menu and
then clicking
Customize
. You can then rearrange commands or add a n
ew toolbar. Across the very bottom of the
IDE is a status bar that displays
Ready
. As you work in the IDE, the status bar changes, displaying messages
related to your current task. For example, the status bar shows information about the progress of a proje
ct you are
building.

Design Mode

When you open or create a project, the appearance of the IDE changes into
design mode
. The IDE in design mode
is shown in the following illustration. This is the visual part of Visual Basic where you design the appearance o
f your
application.

Note:

This topic provides an overview of developing Window Forms applications by using Visual Basic Express,
but you can also create Windows Presentation Foundation (WPF) applications in

Visual Basic Express.
The features described in

this topic are available in WPF applications, but there are additional features,
such as the XAML window. For more information, see
Creating the Visual Look of Your Program:
Introduction

to Windows Presentation Foundation
.

Figure 2: IDE in Design Mode



In design mode, the
Start Page

is covered by another window known as the
Form Designer
, which is basically a
blank canvas that represents the user interface for your application. Notice

that the
Start Page

is still available by
clicking its tab above the
Form Designer
.

When the
Form Designer

is visible, the
Toolbox

contains many controls (representations of buttons, text fields,
grids, and so forth) that can be added to the form and arra
nged as you like. For more information, see
Windows
Forms Designer
.

You will also notice that a new window, the
Properties

window, appears underneath the
Solution Explorer

window. This i
s where you will set the various properties that define the appearance and behavior of the form and
its controls. For more information, see
Setting Properties: Using the Properties Window
.

By default, the Task List window at the bottom of the IDE isn't shown, but it provides a location where you can
keep track of tasks that have to be done or make notes when you are programming. For more information, see
Task List (Visual Studio)
.

If you double
-
click a form or control, a new window called the Code Editor opens. This is where you write the actual
code for your application. More than just a text editor, the Code Editor us
es a technology known as IntelliSense to
help you write code by providing relevant information as you type. For more information, see
Smart Coding: Using
IntelliSense to Help You Write Co
de

and
Visual Basic
-
Specific IntelliSense
.

Note:

For some types of projects, such as
Class Library

projects that have no user interface, the Code Editor
is shown instead of the
Form D
esigner
.

Run Mode

When you run or debug your application, the IDE changes into
run mode
. The application itself is started, and an
additional window related to debugging appears. While in run mode, you cannot make changes in the
Form
Designer
,
Properties

window, or
Solution Explorer
, but you can change your code in the Code Editor.

In run mode, a new window known as the
Immediate

window appears at the bottom of the IDE. If you put the
application into break mode, you can query values and test code in the
I
mmediate

window. Break mode is shown
in the following illustration. For more information, see
Immediate Window
.

Figure 3: Visual Basic form in Break mode



Additional windows for watchi
ng the value of variables, viewing output, and other debugging tasks can be viewed
at run time by selecting them from the
Debug

menu.

Other Important Windows

There are many additional windows that you may encounter in the IDE, each geared to a specific pro
gramming
task. Some of the more common ones are in the following list.



The
Error List

window appears at the bottom of the IDE if incorrect code is entered or other errors occur
at design time. For more information, see
Error List Window
.



The
Object Browser

window is used to examine the properties, methods, and events for any object that
can be used in your application. For more information, see
Object Browser
.



The
Project Designer

is used to configure properties for your application. This includes resources,
debugging behavior, deployment settings, and much more. For more information, see
Introduction to the
Project Designer
.



The
Database Explorer

enables you to view and use existing databases or create and design new ones.
For more information, see
Data Connections in Server Explorer/Database Explorer
.



The XAML window appears at the bottom of the IDE if you are creating a WPF application. For more
information, see
De
signing a User Interface for a WPF Application (Visual Basic)
.

Customization

Visual Basic Express enables you to customize the IDE by rearranging the window layout, choosing which windows
are displayed, adding or removing menu commands and toolbar buttons
, and much more. To learn more about
customizing Visual Studio, see
Customizing the Development Environment

on the

MSDN Web site.


Getting Help

As you work in Visual Basic Express, help is alw
ays just a key
-
press away. Whether you are in the Code Editor or
any other window, pressing the F1 key displays the Help topic most closely related to what you are doing at the
time. For example, if you are in the Code Editor and the cursor is on the keywo
rd
Inherits
, the Help browser is
opened and a topic that describes the use of the
Inherits

statement is displayed.

Note:

The Help files that are included with Visual Basic Express are a subset of the MSDN Library for Visual
Studio Express Editions, which

is in turn a subset of the full MSDN Library. If you are connected to the
Internet, you can access any Help topic in the full library. If you do not have online access or you chose
not to install the MSDN Library for Visual Studio Express Editions, some H
elp topics may not be
available.

Help can also be started from the
Help

menu, and you can find the topics you are looking for by using the
Contents

or
Index

windows or the
Search

tab. For more information, see
Help on Help (Microsoft Document
Explorer Help)
.

Using LINQ in Visual Basic Express

Applications often use data in SQL databases or XML documents. As a developer, you used to need to learn a
secondary language such as SQL or XQuery

to work with this data. Language
-
Integrated Query (LINQ) brings
query capabilities into the Visual Basic language itself so that you don't have to learn a completely different query
language. Now you can use your existing knowledge of Visual Basic, togeth
er with a few additional keywords and
concepts, to query SQL databases, ADO.NET datasets, XML documents, and any .NET Framework collection class
that implements the
IEnumerable

interface.


Advantages of Using LINQ



Familiar syntax for writing queries



Compile
-
time checking for syntax errors and type safety



Improved debugger support



IntelliSense support



Ability to work directly with XML elements, instead of creating
a container XML document, as is required
with W3C Document Object Model (DOM)



In
-
memory XML document modification that is powerful yet simpler to use than XPath or XQuery



Powerful filtering, ordering, and grouping capabilities



Consistent model for working
with data in various kinds of data sources and formats


Writing LINQ Queries

The basic structure of a LINQ

query is the same whether you're working with ADO.NET datasets, SQL databases,
.NET Framework collections, or XML documents. A
query expression

sta
rts with a
From

clause, which is

followed by
query clauses such as
Where

and
Select
. The complete expression is stored in a query variable that can be
executed or modified any number of times.

Query expression syntax resembles the syntax of SQL. For exampl
e,
you could use the following syntax to write a LINQ query that returns all students in a students database that have
science as their major:


Copy Code

Dim StudentQuery = From student in studentApp.students


Where student.Major = "Science" _


Select student

For more information, see
Queries (Visual Basic)
, and
Writing Your First LINQ Query (Visual Basic)
.

There are three basic stages of a LINQ

query. You obtain the data source, define the query expression, and then
run the query. For more infor
mation, see
Writing Your First LINQ Query (Visual Basic)
.


LINQ to Objects

The term
LINQ to Objects

refers to the use of LINQ

to query in
-
memory data structures that support
IEnumerable
.
For more information, see
LINQ to Objects
.


LINQ to SQL

Use LINQ to SQL

to access SQL Ser
ver and SQL Server Express databases through a strongly
-
typed object layer
that you create by using the O/R Designer.

You can use the O/R Designer to map LINQ to SQL classes to tables in a database and then write LINQ queries to
bind data to controls in y
our application. For example, the following LINQ query binds the results of a LINQ query
(all customers from the United States) to a binding source of a
DataGridV
iew

control.


Copy Code

Dim CustomersQuery = From customers in NorthwindSampleDataContext1.Customers
_


Where customers.Country = "U
S" _


Select customers


CustomerBindingSource.DataSource = CustomersQuery

For more information, see
LINQ to SQL
,
O
/R Designer Overview
,
Creating LINQ to SQL Classes: Using the O/R
Designer
, and
Using LINQ to Bind Data to Controls
.

Note:

The O/R Designer does not currently support SQL Server Compact 3.5 databases. For information about
how to obtain SQL Server Express Edition, see the Obtaining SQL Server Express Edition section in
How
to: Install Sample Databases
.


LINQ to DataSet

The
DataSet

is used to bind data to controls in an application. Instead of connecting directly to a

database, you can
use a
DataSet

to create an offline cache of data, which can include subsets of several data sources, to be used with
an application. When the application is

brought online, the database can be updated with the changes in the
DataSet
.

LINQ to DataSet makes querying over cached data faster and easier than the filtering and sorting
methods
available to a
DataSet
. For more information, see
LINQ to DataSet
.


LINQ to XML

LINQ to XML ena
bles you to create and modify XML documents easily by using LINQ query expressions instead of
having to learn XPath or XQuery. LINQ to XML

is a new in
-
memory API for XML that uses modern programming
constructs instead of the W3C DOM. For more information,
see
Overview of LINQ to XML in Visual Basic
,
Including
XML Directly in Your Code: Using XML Literals
, and
Language
-
Integrated Axes in Visual Basic (LINQ to XML)
.

How to: Work with an Existing Application

If you are already familiar with Visual Basic and have an application that you want to work with,
opening an
existing application is easy.

To open an existing application

1.

On the
File

menu, click
Open Project
.

2.

In the
Open Project

dialog box, locate the project to be opened, and click
Open
.

3.

Samples and Resources: Getting Started Quickly

4.

If you are alread
y familiar with Visual Basic and just want to get started, some sample applications and
other programming resources are available on the MSDN Web site. Most samples are fully functional
applications that you can use as is, or you can analyze the code and m
odify them to suit your needs.

5.


Visual Basic Samples and Resources

6.

Visual Basic

samples and resources are available for downloading on the
Samples and Resources

page of
the MSDN Web site. Afte
r you install a sample application, you can find it on the
Start

menu.

Troubleshooting Visual Basic Express

Although Visual Basic Express makes programming easy, you might have to resolve problems that occur as you
create your applications. As you work th
rough the
Visual Basic Guided Tour

or go on to write your own programs,
you may be able to find some help here if you run into problems.


A Lesson in the Guided Tour Doesn't Work

As yo
u work through the lessons in the guided tour, you may find that your program doesn't run or that it doesn't
behave the way that it should. In most cases, errors occur because you skipped a step or mistyped the code.

Tip:

When entering code for a guided
tour lesson, use the
Copy Code

button in the Help topic, and paste the
code into the Code Editor

楴's eas楥r than typ楮i 楴Ⱐand you are 汥ss 汩le汹 to make a m楳take.

ft 楳 a汳o poss楢汥 thatⰠdue to 污te
-
break楮i changes 楮ithe productⰠsteps or code 楮

the 汥sson may be 睲ong⸠qhe
on汩湥 vers楯ns of these top楣s are per楯d楣a汬l updatedⰠso a corrected vers楯n of the top楣 may be ava楬ib汥 on汩湥.

To correct errors in a lesson

1.

Go back to the step in which the program last worked, and carefully follow ea
ch remaining step.

2.

Review any code that you entered and make sure that it exactly matches the code in the lesson.

3.

Press F5 to run the program.

If the program still doesn't run or behave as expected, check to see if an updated version of the topic is
availa
ble. For more information, see "I Can't Access a Help Topic" below.


I Can't Find a Command or Option

The options available in dialog boxes, and the names and locations of menu commands you see, might differ from
what is described in Help, depending on y
our active settings or edition. To change your settings, choose
Import
and Export Settings

on the
Tools

menu. For more information, see
Visual Studio Settings
.


I Can't Access a Help To
pic

The Help files that are included with Visual Basic Express are a subset of the MSDN Library for Visual Studio
Express Editions, which is in turn a subset of the full MSDN Online Library. During installation you had the option of
installing the MSDN Li
brary for Visual Studio Express Editions

if you chose not to install it, consider doing so now.

You can also install either the full
MSDN Library

or the
MSDN Library for Visual Studio Express Editions

by
downloading it from the MSDN Download Center Web site.

A Link Doesn't Work

Links to topics that are not included in the MSDN Library for Visual Studio Express Editions will display the

Information Not Found

page, but you can still access the topics that the links refer to by searching in the MSDN
Online Library.

To access a topic when a link doesn't work

1.

On the
Help

menu, click
Search
.

The
Search Page

opens.

2.

In the search box, enter th
e text that was displayed in the link, and then click
Search
.

A search is performed and the results are displayed.

3.

Select the
MSDN Online

tab on the right
-
hand side of the
Search
page.

Note:

If
MSDN Online

is not displayed, your Help system may not be co
nfigured for online access. For more
information, see "How to: Enable Online Access" below.

4.

Click the topic title that most closely matches the text of the original link.

The topic is downloaded and displayed.

Pressing F1 Doesn't Work

Pressing F1 anywhere

in the IDE should display context
-
sensitive Help. Even though not all topics are included in
the MSDN Library for Visual Studio Express Editions, if you are connected to the Internet, you can access any Help
topic in the full library using F1. If you do n
ot have online access or you chose not enable online Help, some help
topics may not be available using F1.

You can change you Help options at any time as described below.

How to: Enable Online Access

The first time you access help from Visual Basic Express

you are prompted to choose how online Help is configured.
The choices are to try and find the online version of a topic first, to try locally installed Help first and look online if
it isn't found, or to use local Help only.

Tip:

If you have access to t
he Internet, you should configure Help so that it checks online Help first

楦 a
ne睥r vers楯n of a top楣 楳 ava楬ib汥Ⱐyou 睩汬 a汷lys have the most up
-

-
date 楮iormat楯n 楦 you search
for the top楣 or use cㄮ

You can change you ee汰 opt楯ns at any t業e
as descr楢ed be汯眮

Note:

To access online Help, you must have an active connection to the Internet, and any proxy server or
firewall must be configured to allow access to the MSDN online library.

To enable online access

1.

If it is not already open, open
Visual Basic from the Windows
Start

menu.

2.

On the
Tools

menu, click
Options
.

3.

In the
Options

dialog box, select the
Show All Settings

check box.

4.

Expand the
Help

node under
Environment
, and then click
Online
.

5.

In the
When loading Help content
box, click eith
er
Try online first, then local
, or
Try local first,
then online
.

You should now be able to access online Help.

Note:

When you click a link in a local topic, it will not automatically take you to the online version of the topic.
If you receive the
Inform
ation Not Found

page, you can search for the title of the topic to retrieve the
online version of the topic.


My Database Isn't Reflecting Changes

A local database file can be included as a file in a project. The first time you connect your application
to a local
database file, you can choose between creating a copy of the database in your project or connecting to the existing
database file in its current location.

If you choose to create a copy of the database, depending on the file settings, it is poss
ible that a new copy of the
database is being created each time the project is run, overwriting the version that contains your changes. For
more information, see
How to: Manage Local Data Files i
n Your Project
.

Creating Your First Visual Basic Program

The best way to learn programming with Visual Basic is to actually create a program. The following exercises
discuss the process of creating a program for viewing Web pages.

If you don't understand

everything immediately, don't worry

the concepts introduced here will be discussed in
detail in other sections of the
Visual Basic Guided Tour
.

For a video version of this topic, see
Video How to: Creating Your First Visual Basic Program
.


In This Section

Step 1: Create a Project in Visual Basic


Describes

how to create a project for your Web
-
browsing program.

Step 2: Create a User Interface


Describes how to add controls to the form to create the user interface of the Web
-
browsing progra
m.

Step 3: Customize Looks and Behavior


Describes how to change the properties of the controls on the Web
-
browsing program.

Step 4: Add Visual Basic Code


Describes how to add code to the event handler of a button in the Web
-
browsing program.

Step 5: Run and Test Your Program


Describes how to run th
e Web
-
browsing program to test its functionality.


Related Sections

Closer Look: Understanding Properties, Methods, and Events


Provides an overview of the methods, properties, and eve
nts of an object.

Closer Look: Understanding Control Layout


Describes how to arrange, align, and resize controls on a Windows form.

Project Types in Visual Basic Express


Describes the project types available in Visual Basic Express.

Introduction to the Visual Basic Programming Language


Introduces t
he basics of the Visual Basic language.

Creating the Visual Look of Your Program: Introduction to Windows Forms


Describes how to use forms and controls to create a user interface.

Step
1: Create a Project in Visual Basic

For your first Visual Basic program, you will create a Web
-
browsing application that opens a Web page. Your first
step in creating a Visual Basic program is to open Visual Studio and create a
project
. You will do this wh
en you
create any Visual Basic program.


For a video version of this topic, see
Video How to: Creating Your First Visual Basic Program
.

To create a project for your program

1.

From the Windows
Star
t

menu, click Visual Basic 2008 Express Edition.

The "Welcome to Visual Basic Express" screen appears. This is the interface for Visual Basic 2008 Express
Edition, also known as the
integrated development environment

or
IDE
.

2.

On the
File

menu, click
New Pr
oject
.

The
New Project

dialog box opens.

3.

Select
Windows Forms Application

and click
OK
.

A new
form

displays in the IDE, and the necessary files for your project are added to the
Solution
Explorer

window. If this is the first
Windows Forms Application

proje
ct that you have created, it is
named "WindowsApplication1".


Closer Look

You just created a project for the Web
-
browsing program. A project in Visual Basic is a place to store the pieces of
your program and keep those pieces organized.

When you first cr
eate a new project, it exists only in memory. If you close the Visual Basic IDE, you are prompted
to save or discard the project. When you save it, you can give it a more meaningful name.

When you opened the
New Project

dialog box, there were several types

of projects to choose from. Your Web
-
browsing program is a regular
Windows
-
based Application,

that is, a program that can be run from your
Start

menu.

When you created the project, a form (also known as a form
designer
) displayed in the IDE. This form rep
resents a
window that will display when the program is run. Many programs display more than one window, so a project can
contain multiple forms.


Next Steps

In the next lesson, you will learn how to add controls to the form to build the Web
-
browsing appl
ication.

Next Lesson:
Step 2: Create a User Interface

Step 2: Create a User Interface

It is now time to start to build the Web browser. You will use Visual Basic Express to build the
use
r interface

(the
visible part that users interact with) by adding
controls

from the
Toolbox

to the form.

The
Toolbox

is on the left side of Visual Studio and consists of several tabs such as
Data
,
Components
, and
All
Windows Forms
. Inside each tab is a set

of entries that represent controls or components that you can add to
your application. For example, the
All Windows Forms

tab has entries named
TextBox
,
Button
, and
CheckBox

that represent controls that you can add to your application by dragging them ont
o the form. Don't worry too much
about the size of the controls; you will learn how to customize the look of your application in the next lesson.

For a video version of this topic, see
Video How
to: Creating Your First Visual Basic Program
.

To add controls to your application

1.

Click the
Toolbox

panel.

The
Toolbox

opens.

Note:

The
Toolbox

is easier to use if you keep the window open. You can do this by clicking the
Auto Hide

icon, which looks lik
e a push pin.

2.

Click the
All Windows Forms

tab of the
Toolbox
, and then drag a
Panel

control to the top
-
left corner of
the form.

Note:

If you have difficulty finding the correct control, right
-
click the
Toolbox

and then select
Sort Items
Alphabetically
.

3.

From the same tab, drag a
TextBox

control and position it on top of the
Panel
.

Note:

You can reposition controls by using a drag
-
and
-
drop operation. You can also resize controls by clicking
and dragging the edge or corner of the control.

4.

From the same
tab, drag a
Button

control and position it on top of the
Panel
, to the right of the
TextBox

control.

5.

Finally, from the
All Windows Forms

tab, select a
WebBrowser

control and position it under the
Panel
.

Note:

If the
WebBrowser

control does not fit on the

form, you can resize the form by dragging the edge or
corner of the form.

Note:

If you kept the
Toolbox

window open, you may want to close it now to give yourself more room to
work. You can do so by clicking the
Auto Hide

icon again.


Closer Look

Yo
u just added four controls to the form. Controls contain code that defines what the controls look like and what
tasks they can perform.

Take, for example, the
Button

control


most programs have an "OK" button or an "Exit" button. While you could
write your

own code to draw a button on the screen, change its appearance when it is pressed, and perform some
task when it is clicked, doing this for every program would quickly become tedious. The
Button

control already
contains the code that is required to do the
se things. This saves you a lot of unnecessary work.

As you can see, the
Toolbox

contains many controls, and each control has a unique purpose.
Panel

controls can
be used to hold other controls, such as the ones that you just added.
Button

controls are typ
ically used to perform
tasks when the user clicks them, for example, closing the program.
TextBox

controls are used to enter text on a
screen through the keyboard. A
WebBrowser

control provides built
-
in Web
-
browsing capabilities similar to
Internet Explore
r

you definitely wouldn't want to write all the code for that!

In upcoming lessons you will learn how to customize the appearance of these and many other controls, and how to
write code that defines their behavior. In addition to using the
Toolbox

controls
, you can also create your own
controls known as
user controls

these are also covered in an upcoming lesson.


Next Steps

You just added all the necessary controls for your application. It probably looks rough and unfinished

because it
is! In the next les
son, you will use the
Properties

window to set the properties that will control the appearance
and behavior of your application.

Next Lesson:
Step 3: Customize Looks and Behavior

Step 3:

Customize Looks and Behavior

In the previous lesson, you created a user interface by adding controls to your application. However, at this point it
neither looks like nor functions as a finished application. In this lesson, you will set
properties

to cont
rol the
appearance of your controls by using the
Properties

window.

For a video version of this topic, see
Video How to: Creating Your First Visual Basic Program
.

To set the properties of your c
ontrols

1.

In the
Form Designer
, select the
Panel

control.

The
Properties

window in the lower
-
right corner of the IDE displays all properties for the
Panel

control
named
Panel1
.

2.

In the
Properties

window, select the
Dock

property, and then click the arrow to t
he right. A small
property
-
selection window with several boxes is displayed.

Tip:

The
Dock

property is found under the
Layout

category. You can sort the properties alphabetically by
clicking the
AZ

button in the
Properties

window.

3.

Click the top box in
the property
-
selection window to set the
Dock

property to
Top
. The
Panel

control
expands to fill the top of the form.

4.

In the
Properties

window, click the plus sign (+) next to the
Size

property to expand it.

The
Width

and
Height

properties become visible i
n the
Properties

window.

5.

In the
Properties

window, notice that the
Height

property of the
Panel

control is set to
100
. Change this
property value to
50
.

6.

In the
Form Designer
, select the
WebBrowser

control. In the
Properties

window, set its
Dock

property to

Fill

by selecting the
Dock

property, clicking the arrow to the right, and selecting the center
box in the property
-
selection window.

7.

In the
Form Designer
, select the
Button

control.

8.

In the
Properties

window, select the
Text

property of the
Button

control.

In the right column, delete
Button1

and replace it with
Go!
.

9.

Resize or relocate any one of the controls, and resize the form to suit your taste. For example, you might
want to increase the length of the
TextBox

control so that it is long enough to display

a valid URL. The
following illustration shows an example of what the Web Browser application might look like.

Web Browser application



Note:

The
TextBox

and
Button

controls must remain on top of the
Panel
, or you will not be able to see them
when you
run the application.


Closer Look

In this lesson, you set several
properties

that changed the appearance of the controls for your application. A
property in Visual Basic represents an attribute of an object

in this case, a control. For example, one attr
ibute of a
Button

control is the text it displays. In this case, you set the
Text

property to display "Go!". To learn more about
properties, see
Closer Look: Understanding Properties, Met
hods, and Events
.

Properties can take many different types of values besides text. For example, the
Dock

property used a property
-
selection window to show available options. Other property values might be numbers, an option that you select
from a list, o
r a true
-
or
-
false option.

If you resized or relocated a control, you also set properties. The
Size

and
Location

properties determine the
control's size and location on the form. To see this in action, select the
Size

property in the
Properties

window
and
use the mouse to resize the control. When you release the mouse, the new
Size

values display in the
Properties

window. To learn more about control layout, see
Closer Look: Understanding C
ontrol Layout
.

In addition to setting properties in the
Properties

window, most properties can be set by writing code. You will
learn more about how to write code to set properties in a following lesson.


Next Steps

Your user interface is now complete!
All you have to do is add the instructions (also called
code
) for how you want
your program to work. In the next lesson, you will add a line of code to your program.

Next Lesson:
Step 4:
Add Visual Basic Code

Closer Look: Understanding Properties, Methods, and Events

All objects in the Visual Basic language have their own properties, methods, and events. This includes forms and
controls. Properties can be thought of as the attributes of a
n object, methods as its actions, and events as its
responses.

An everyday object such as a helium balloon also has properties, methods, and events. A balloon's properties
include visible attributes such as its height, diameter, and color. Other properties

describe its state (inflated or
deflated), or attributes that are not visible, such as its age. All balloons have these properties, although the values
of these properties may differ from one balloon to another.

A balloon also has known methods or actions

that it can perform. It has an inflate method (filling it with helium), a
deflate method (expelling its contents), and a rise method (letting go of it). Again, all balloons can perform these
methods.

Balloons also have responses to certain external events
. For example, a balloon responds to the event of being
punctured by deflating, or to the event of being released by rising.


Properties, Methods, and Events


A balloon has properties (Color, Height, and Diameter), responds to events (Puncture), and can

perform methods
(Deflate, MakeNoise).

Properties

If you could program a balloon, the Visual Basic code might resemble the following "code," which sets a balloon's
properties.

Balloon.Color = Red


Balloon.Diameter = 10


Balloon.Inflated = True

Notice the o
rder of the code

the object (Balloon), followed by the property (Color), followed by the assignment of
the value (= Red). You could change the balloon's color by substituting a different value.

Methods

A balloon's methods are
called

as follows.

Balloon.Inf
late

Balloon.Deflate

Balloon.Rise(5)

The order resembles that of a property

the object (a noun), followed by the method (a verb). In the third method,
there is an additional item, called an
argument
, which specifies the distance the balloon will rise. Some

methods
will have one or more arguments to further describe the action to be performed.

Events

The balloon might respond to an event as follows.


Copy Code

Sub Balloon_Puncture()


Balloon.MakeNoise("Bang")


Balloon.Deflate


Balloon.Inflated = False

End Sub

In this case, the code describes the balloon's behavior when a Puncture event occurs. When this event occurs, call
the MakeNo
ise method with an argument of "Bang" (the type of noise to make), then call the Deflate method.
Since the balloon is no longer inflated, the Inflated property is set to
False
.

While you can't actually program a balloon, you can program a Visual Basic form

or control. As the programmer,
you are in charge. You decide which properties should be changed, which methods should be invoked, or which
events should be responded to in order to achieve the desired appearance and behavior.


Next Steps

In the next les
son, you will add a line of code to your program.

Next Lesson:
Step 4: Add Visual Basic Code
.

Closer Look: Understanding Control Layout

You can arrange controls in many ways when you add

them to forms. For example, you might want to arrange
three buttons on a form in a column, or you might want to arrange them side by side. This arrangement of controls
is known as the
layout
. There are many tools and techniques that you can use in Visual
Basic to help you arrange
and

resize the controls you add to a form. In this topic, you will look at some of these techniques.


Control Placement

There are typically two ways you can arrange controls on a form. After you have dragged a control to the for
m, you
can use the
Properties

window to set precise positioning. Alternatively, you can move the control manually by
dragging it to a specific location on the form. You will typically use a combination of these techniques when you
design your applications.


Aligning Controls

When you add controls to a form, you can arrange the controls so that they line up with an edge of the form. You
can also align controls with other controls that are already on the form. You can even set them up to automatically
resiz
e whenever the application is resized.

Aligning Controls to the Edge of a Form

You might want to align a control so that it is attached to the edge of the form. This is known as
docking

the
control. There is an example of this in
Step 3: Customize Looks and Behavior
, which shows how to align a
Panel

control to the top of a form by setting its
Dock

property to
Top
.

You can dock a control to any edge of a form (top,

bottom, left, or right), and the control will stay aligned even if
the form is resized. For example, if you dock a control to the top a form and then change the width of the form, the
control automatically resizes to fit the new width. When you dock a con
trol to all sides of a form, it is the same as
setting the
Dock

property to
Fill
. This is because you fill the entire form with the control.

Note:

If you have a control docked to one edge of a form and then set the
Dock

pro
perty of a second control
to
Fill
, the second control fills only the remaining space.

Aligning Controls with Other Controls

You can align a control with other

controls on the form by dragging it. If you drag a control on the form in the
same area of an existing control, you'll notice that blue lines appear. These lines are guides that make it easy for
you to see exactly where to drop the control so that it alig
ns with an existing control. The following illustration
shows these alignment lines.

Aligning controls



Tip:

You can also select multiple controls and use the align commands on the
Layout

toolbar.


Resizing Controls

When you select a control, a numb
er of small square symbols appear around the boundary of the control. These
symbols are called
sizing handles
. To resize the control, click the sizing handle and drag it to a new location to
make the control larger or smaller. The following illustration sh
ows how the pointer changes to an arrow when you
move it over a sizing handle. The arrow indicates the directions in which you can drag the control to resize it.

Control sizing handles



You can set controls to automatically resize when the form is resize
d by setting the
Dock

property of the control to
Fill
. You saw a
n example of this in
Step 3: Customize Looks and Behavior
, where you learned how to dock a
Web
Browser

control so that it filled an area of the Windows Form. When you increase the size of the Windows
Form, the
WebBrowser

control automatically resizes to fit

the form.

If you prefer, you can also resize controls to a specific measurement by setting the
Height

and
Width

properties for
the control in the
Properties

window.

Note:

You can find the
Height

and
Width

properties of a control under the
Size

property in the
Properties

window.


N
ext Steps

In the next lesson, you will add a line of code to your program.

Next Lesson:
Step 4: Add Visual Basic Code
.

Step 4: Add Visual Basic Code

In the previous lesson, you used the

Properties

window to configure the properties of the controls on a form. In
this lesson, you will add the
code

that will control your program's functions.

For a video version of this topic, see
Video How to: Creating Your First Visual Basic Program
.

To add code and functionality to your program

1.

In the
Form Designer
, double
-
click the
Button

control.

A new window called the Code Editor opens. This is where you add all the code for your program.

2.

In

the Code Editor, type the following.

Visual Basic


Copy Code

WebBrowser1.Navigate(Textbox1.Text)

This code will
run

when users click th
e button.

Tip:

When the Code Editor opens, the pointer is automatically located inside the Button's procedure

you can
just start to type code.


C汯ser iook

You may have noticed that when the Code Editor opened, it already contained some code that look
ed like this:

Private Sub Button1_Click(ByVal sender As System.Object...

|

End Sub

This code is an
event handler
, also called a
Sub

procedure. Any code inside this procedure (between
Sub

and
End
Sub
) runs every time that the button is clicked. You may also

have noticed that the pointer was located inside the
event procedure, so all that you had to do was type the code.

The code that you typed (
WebBrowser1.Navigate(TextBox1.Text)
) tells the program to take the text that was
typed into TextBox1 and pass it as

an
argument

to the
Navigate

method

of the
WebBrowser

control (named
WebBrowser1). To learn more about properties, methods, and events, see
Closer Look: Understanding Properties,
Methods,

and Events

If you don't understand the code, don't worry

you will learn much more about how to write code in following
lessons.

Next Steps

Your application is now complete! In the next lesson, you will run your first Visual Basic application.

Next Lesson
:
Step 5: Run and Test Your Program


See Also

Step 5: Run and Test Your Program

Now that your program is complete, it is time to run and test it. For complex programs, testing can be a

long and
difficult process, which will be discussed in detail in a later lesson. Happily, for this program, all that you have to do
is run it!

For a video version of this topic, see
Video How to
: Creating Your First Visual Basic Program
.

To run your program

1.

Connect your computer to the Internet.

2.

On the
Debug

menu of the Visual Basic IDE, click
Start Debugging
.

This command runs your program.

Tip:

A shortcut to run your program is to press F5.

3.

In the text box, type
http://www.microsoft.com

and click the
Go!
button.

The
WebBrowser

control in your program goes to the Microsoft home page. From there, you can
navigate through any related links. To visit another Web page, type the address in the tex
t box and click
the
Go!
Button.

4.

To close the program, on the
Debug

menu, click
Stop Debugging
.

Tip:

You can also end the program by clicking the
Close

button on the top
-
right corner of the form.


Closer Look

In this lesson you ran your program to see
whether it worked. For most Visual Basic programs, you will repeat this
process many times. Typically after you add some new code, you will run the program to see whether the code
does what you expected it to do. If it doesn't, you will have to fix it. Thi
s process is referred to as

debugging
; it will
be discussed in detail in a later lesson.

You might be surprised that your program moves to a Web page and displays it, all as a result of you writing a
single line of code. This is the beauty of Visual Basic

all the necessary code is built into the
WebBrowser

control.
This saves you work. If you had to do it all yourself, it would take hundreds or even thousands of lines of code!

Troubleshooting

If your program does not run or display the Web page, there are s
ome things that you can check:



Make sure that you are connected to the Internet. Open Internet Explorer and try to move to the Microsoft
home page. If it works in Internet Explorer, it should also work in your program.



Make sure that you typed the address
(
http://www.microsoft.com
) correctly.



Go back and check
Step 2: Create a User Interface

and make sure that you put the correct controls on the
form.



Go back to
Step 4: Add Visual Basic Code

and make sure that you typed the code correctly.

Next Steps

Congratulations! Your first Visual Basic program is finished. You have demonstrated how powerful programs can be
developed

quickly and easily by using Visual Basic. In the following lessons, you will be introduced to some
features of the IDE.

Next Lesson:
Introduction to the Visual Basic Express IDE

Introdu
ction to the Visual Basic Express IDE

The Visual Basic Express integrated development environment (IDE) makes it easy for you to create programs for
Microsoft Windows. The IDE contains several tools that help you design your applications and write, edit, a
nd
debug your application code. The following links will help you to familiarize yourself with the Visual Basic Express
IDE.



In This Section

Exploring Your Solution: Using Solution Ex
plorer


Explains how to use
Solution Explorer

to manage your project files.

Rummaging Through the Toolbox


Explains how to find controls in the
Toolbox

and add them to an application.

Setting Properties: Using the Properties Window


Explains how to set the properties of controls in a Windows Forms application.

Smart Coding: Using IntelliSense to Help You Write Code


Explains how IntelliSense can make your coding tasks easier.

Keyboard Shortcuts: Navigating the IDE by Using the Keyboa
rd


Lists the most common keyboard shortcuts that can help you to quickly perform tasks in the Integrated
Development Environment (IDE).

Exploring Your Solution: Using Solution Explorer

Solution Explorer

is an area of the integrated development environmen
t (IDE) that contains your solution and
helps you manage your project files. The files are displayed in a hierarchical view, much like that of Windows
Explorer. By default,
Solution Explorer

is located on the right side of the IDE. If
Solution Explorer

is
not visible,
you can click the
View

menu and then click
Solution Explorer

to open it.

When you create a new Windows Forms application by using Visual Basic Express, a Windows Application solution
appears in
Solution Explorer
. The solution contains two node
s:
My Project

and
Form1.vb
, as the following
diagram illustrates.



Note:

By default, there are actually other files in
Solution Explorer
, but they are hidden. If you click the
Show All Files button, you can see all the files associated with the project
.

The
My Project

node opens the
Project Designer

when you double
-
click it. The
Project Designer

gives you
access to project properties, settings, and resources. For more information, see
Introduction to the Project
Designer
. The
Form1.vb

node is the Windows Form in your solution. You can view this file in Design view, which
enables you to see the form and any controls that you have added to it. You can also view this file in the Code
Edi
tor, which enables you to see the code associated with the application you're creating.


Try It!

To view project files in Solution Explorer

1.

On the
File

menu, click
New Project
.

The
New Project

dialog box appears.

2.

Click
Windows Forms Application

and then
click
OK
.

3.

If
Solution Explorer

is hidden, click the
View

menu and then click
Solution Explorer
.

4.

Right
-
click
Form1.vb

in
Solution Explorer
, and then click
View Code
.

The Code Editor appears.

5.

Right
-
click
Form1.vb

in
Solution Explorer

again, but this time cl
ick
View Designer
.

The Windows Form appears in Design view.


Adding Project Items

You can add items, such as another Windows Form, to your project by clicking the
Project

menu, and then clicking
Add New Item
. However, you can also add project items in
So
lution Explorer
.

To add a project item in Solution Explorer

1.

In
Solution Explorer
, right
-
click the solution (
WindowsApplication1
), point to
Add
, and then click
New Item
.

The
Add New Item

dialog box appears.

2.

Click
Windows Form
, and then click
Add
.

A new for
m is added to your solution, and
Form2.vb

appears in
Solution Explorer

underneath
Form1.vb
.


Next Steps

In this lesson, you learned how to use
Solution Explorer

to perform project management tasks, such as switching
from Design view to the Code Editor. Y
ou also learned how to add a new project item to your solution.

In the next lesson, you will learn about the
Toolbox

and how to find the controls you need to create an
application.

Next Lesson:
Rummaging Through the Toolbox

Rummaging Through the Toolbox

The
Toolbox

is a container for all the controls that you can add to a Windows Forms application or a Windows
Presentation Foundation (WPF) application. By default, the
Toolbox

is located o
n the left side of the integrated
development environment (IDE). If the
Toolbox

is not visible, you can click the
View

menu, and then click
ToolBox

to display it. The following illustration shows the common controls in the
Toolbox
.

Common controls in the T
oolbox



You can set the
Toolbox

to automatically hide when you're not using it, or you can set the
Toolbox

to always be
visible in the IDE. This makes it easier for you to see all the controls while you create your application. The controls
are not visib
le on the
Toolbox

when you are in the Code Editor.

To add controls to your application, you can drag them directly from the
Toolbox

to the form.


Try It!

To open the Toolbox and add a control to a Windows Form

1.

On the
File

menu, click
New Project
.

The
New

Project

dialog box appears.

2.

Click
Windows Forms Application

and then click
OK
.

3.

If the
Toolbox

is closed, click the
View

menu, and then click
Toolbox
.

When the
Toolbox

is hidden, you can see a small tab labeled
Toolbox

at the upper
-
left side of the IDE.
T
o make the
Toolbox

visible, move the mouse pointer over this tab. The
Toolbox

disappears again when
the mouse pointer leaves the
Toolbox
.

4.

To cause the
Toolbox

to stay open, click the pushpin icon in the upper
-
right corner of the
Toolbox
.

Note:

The pushpi
n icon appears in a horizontal position when it is set to
Auto Hide
; otherwise, it appears in a
vertical position.

5.

Expand the
Common Controls

tab on the
Toolbox

if it's not already expanded, and then locate the
Button

control.

Tip:

To sort the controls

alphabetically, right
-
click the
Toolbox
, and then click
Sort Items Alphabetically
.

6.

Drag a
Button

control from the
Toolbox

to the form.

Note:

You can also add a control by clicking the control in the
Toolbox

and then clicking an area of the form,
or by
double
-
clicking the control in the
ToolBox
.

7.

Click the pushpin icon again to hide the
Toolbox
.


Toolbox Tabs

By default, the controls in the
Toolbox

are organized alphabetically within tabs that contain related controls. To
expand a tab, click the plus (
+) sign next to the tab name. To collapse an expanded tab, click the minus (
-
) sign
next to the tab name.

The types of controls that are visible in the
Toolbox

depends on the type of applications that you are creating. For
Windows Forms projects, the follo
wing tabs are visible in the
Toolbox
.

Tab name

Description

All Windows
Forms

Contains all the standard Windows Forms controls that are available in the
Toolbox
.

Common
Controls

Contains the most common controls that are typically used in Windows
-
based
ap
plications.

Containers

Contains controls that hold other controls, such as
GroupBox

controls and
Panel

controls. Containers can help isolate a set of controls from other controls on the
form.

Menus and
ToolBars

Contains controls that enable you to create menus and toolbars for your application,
such as the
MenuStrip

and
ToolStrip

controls.

Data

Contains controls that help you easily work with data i
n your application, such as
the
DataGridView

control.

Components

Contains components that typically do not have a user interface, such as the
Timer

and the
ErrorProvider
.

Printing

Contains controls that enable you to provide printi
ng capabilities to an application.

Dialogs

Contains controls that let you use common dialog boxes in your application, such as
the
SaveFileDialog
,
FolderBrowserDialog

and
FontDialog

controls.

You will learn more about
the controls on these tabs when you create Windows Forms applications in
Creating the
Visual Look of Your Program: Introduction to Windows Forms
.


WPF Controls

Windows Presentation Fou
ndation (WPF)

provides new techniques for developing enhanced graphical user
interfaces. When you create a WPF application, several WPF controls become available on the
Toolbox
. These
controls are also grouped onto several tabs. When you are creating a WPF

Application project, the following tabs
are visible in the
Toolbox
.

Tab name

Description

All Controls

Contains all the standard WPF controls that are available in the
Toolbox
.

Common
Controls

Contains the most common controls that are typically used in
WPF applications.

All Containers

Contains controls that hold other controls, such as
Canvas

and
Frame

controls.
Containers can help isolate a set of controls from other controls on the form.

Common
Containers

Contains the most common containers that are
typically used in WPF applications

Menus and
ToolBars

Contains controls that enable you to create menus and toolbars for your application,
such as the
Menu

and
ContextMenu

controls.

You will learn more about the controls on these tabs when you create WPF

applications in
Creating the Visual Look
of Your Program: Introduction to Windows Presentation Foundation
.


Next Steps

In this lesson, you learned how to navigate the
Toolbox

and how
to add a
Toolbox

item to a Windows Forms
application.

In the next lesson, you will learn how to set the properties of controls by using the
Properties

window.

Next Lesson:
Setting Propert
ies: Using the Properties Window
.

Setting Properties: Using the Properties Window

All objects in the Visual Basic language, including forms and controls, have their own attributes that describe them.
These attributes are known as
properties
. You can set t
he properties of a form and any controls on the form in the
integrated development environment (IDE) by using the
Properties

window or by writing code in the Code Editor.
For example, if you want to display text on a button, you can set the button's
Text

property, as shown in the
following illustration.


Properties Window




Try It!

To set the properties of a control

1.

On the
File

menu, click
New Project
.

The
New

Project

dialog box appears.

2.

Click
Windows Forms Application

and then click
OK
.

3.

Drag a
Button

control from the
Toolbox

to the form.

4.

If the
Properties

window is hidden, click the
View

menu, and then click
Properties Window
.

5.

Click the
Button

control and scr
oll through the properties in the
Properties

window to become familiar
with them.

6.

Click the
Text

property, and then type
Submit

in the right
-
hand column.

When you click an empty space in the Windows Forms Designer, the text on the button changes to
Submit
.


Docking a Control

You can dock a control to a location on a form so that it remains in the same location, even when the form is
resized. For example, you can dock a control to the top of the form. This causes the control to appear at the top of
the for
m, and causes it to extend from the left side of the form to the right side. If a user resizes the form, the
control will remain docked to the top of the form, and it will expand to the width of the form.

You can choose to dock a control at the top, bottom
, left, or right of a form. You can also choose to fill the form
with the control. In the
Properties

window, when you click the drop
-
down arrow associated with the
Dock

property, a menu appears containing boxes that represent the top, left, center, right,
and bottom of the form. If
you click in the left square, the control will dock to the left side of the form. If you click in the center square, the
control will fill the whole form.

To set the Dock property of a control

1.

Click the
Button

control and press t
he DELETE key to delete it from the form.

2.

Drag a
RichTextBox

control from the
Toolbox

to the form.

3.

Click the drop
-
down arrow next to the
Dock

property, and then c
lick the center square.

The
RichTextBox

control expands to fill the whole form.


Next Steps

In this lesson, you learned how to set the properties of a control b
y using the
Properties

window.

In the next lesson, you will learn how IntelliSense can help you write code quickly.

Next Lesson:
Smart Coding: Using IntelliSense to Help You Write Code

S
mart Coding: Using IntelliSense to Help You Write Code

The Visual Basic integrated development environment (IDE) helps you write code with fewer keystrokes and fewer
errors by providing lists of the available keywords, variables, and members (methods, prop
erties, and events). The
IDE also completes words as you type your code. In Visual Basic, you can get all the help you need right in the
Code Editor, while you type your code.


IntelliSense Features

There are several features of IntelliSense that can mak
e your coding tasks easier. These include List Members,
Parameter Info, Quick Info, Complete Word, and Syntax Tips, and also some new features introduced in Visual
Basic 2008.

List Members

When you type the name of a type or namespace in the Code Editor, a

list of all the valid methods, properties, and
events becomes available in a drop
-
down list. An example of code written within a method that displays the list