CHAPTER TWO
Creating Simple Visual Basic
.NET Windows Applications
2- 2
Chapter Introduction
• The Integrated Development Environment (IDE)
is used for modern software development.
• The IDE contains tools to write code, build a
GUI , and test and debug applications.
• Overview of the application construction
process.
• Design issues are addressed.
• Visual Basic .NET controls are examined.
• The MsgBox statement and InputBox() function
are visited.
• A project is developed as a working application.
McGraw-Hill/Irwin
©2002 by The McGraw-Hill Companies, Inc. All rights reserved.
2- 3
Objectives
• Design and construct simple complete
applications from scratch.
• Explain the structure of Visual Basic .NET.
• List the characteristics of several Visual
Basic .NET controls.
• Identify the purpose of each major control of
the Visual Basic .NET IDE.
• Explain basic programming practices that
contribute to the readability of programs.
McGraw-Hill/Irwin
©2002 by The McGraw-Hill Companies, Inc. All rights reserved.
2.1 From New Solution to Finished
Application
• Overview of the Construction Process
– Visual Basic .NET runs under Windows.
– The programmer creates the application.
– The project is an application under
construction.
– The application is saved to disk periodically.
– An executable file is generated from the
finished application program.
McGraw-Hill/Irwin
©2002 by The McGraw-Hill Companies, Inc. All rights reserved.
2- 4
2- 5
Visual Basic .NET’s Three Modes
• Design Mode
– Placing, arranging, and customizing the
appearance of buttons, labels, and other
controls on a form.
– Writing processing scripts (source code).
– Saving the solution.
– Making an executable file.
McGraw-Hill/Irwin
©2002 by The McGraw-Hill Companies, Inc. All rights reserved.
Visual Basic .NET’s Three Modes
(cont.)
• Run Mode
– Executes the solution.
– Used to evaluate the workability of a part of
the project.
– Used to show the user how the solution will
work.
McGraw-Hill/Irwin
©2002 by The McGraw-Hill Companies, Inc. All rights reserved.
2- 6
Visual Basic .NET’s Three Modes
(cont.)
• Break Mode
– Helps the developer with debugging.
– Enables the developer to switch back to run
mode or design mode.
McGraw-Hill/Irwin
©2002 by The McGraw-Hill Companies, Inc. All rights reserved.
2- 7
2- 8
Design Time and Run Time
• In design mode, the project is in design time.
• In run mode, the project is in run time.
• Some errors can be found and corrected in
design time.
• Other errors can only be detected during run
time.
McGraw-Hill/Irwin
©2002 by The McGraw-Hill Companies, Inc. All rights reserved.
2- 9
2.2 Overview of Controls
• Standard controls are used to create userfriendly applications.
• Standard controls help users lower the
learning curve for new programs.
McGraw-Hill/Irwin
©2002 by The McGraw-Hill Companies, Inc. All rights reserved.
2- 10
Categories of Controls
• Trigger: Initiate processing
– Ex. Button, MainMenu, and Timer
• Input: Get data from user
– Ex. TextBox, RadioButton, and CheckBox
• Output: Display results to user
– Ex. Label, DataGrid, and ListView
McGraw-Hill/Irwin
©2002 by The McGraw-Hill Companies, Inc. All rights reserved.
2- 11
Categories of Controls (cont.)
• Organize: Group other controls
– Ex. Form, GroupBox, and Panel
• Data Access: Interface with databases
– Ex. Entire Data Group and DataGrid
McGraw-Hill/Irwin
©2002 by The McGraw-Hill Companies, Inc. All rights reserved.
2- 12
The Correct Control for the Job
• Chose controls to satisfy user requirements.
• Different controls are good for different tasks.
• The Button, Label, and Textbox controls are
introduced.
McGraw-Hill/Irwin
©2002 by The McGraw-Hill Companies, Inc. All rights reserved.
2.3 The Visual Basic .NET
Development Environment
2- 13
• The IDE helps develops create efficient and
effective solutions.
• The IDE for Visual Basic .NET is common to
all the other tools available in the Visual
Studio. NET suite.
McGraw-Hill/Irwin
©2002 by The McGraw-Hill Companies, Inc. All rights reserved.
2- 14
Getting Started
• Open an existing project or begin a new
project from the Start Page.
• Use the My Profile option to set up the IDE.
McGraw-Hill/Irwin
©2002 by The McGraw-Hill Companies, Inc. All rights reserved.
Visual Basic .NET Solution
Structure
2- 15
• Every application will be organized as a
“solution.”
• Solution Explorer is an interface for viewing
and managing containers and associated
items.
• Items are files that make up your project,
such as forms, source files, and classes.
McGraw-Hill/Irwin
©2002 by The McGraw-Hill Companies, Inc. All rights reserved.
Main Tools Used in Visual Basic
.NET
•
•
•
•
•
Menu
Toolbar
Solution Explorer
Properties Editor
Task List
McGraw-Hill/Irwin
•
•
•
•
2- 16
Toolbox
Designer Window
Code Window
Help System
©2002 by The McGraw-Hill Companies, Inc. All rights reserved.
2- 17
Saving a Solution
• Save your solution and all its contents on a
regular basis.
• Each project should be in its own separate
folder.
• Avoid the temptation to use the Save As…,
save option.
ã Use the Save and Save All Toolbar icons.
McGraw-Hill/Irwin
â2002 by The McGraw-Hill Companies, Inc. All rights reserved.
2- 18
Summary
• Many of the features of the Visual Basic .NET
IDE have been introduced.
• Next, some of the controls to write simple
programs will be introduced.
• Experimentation is encouraged.
• Hands-on experience is important.
McGraw-Hill/Irwin
©2002 by The McGraw-Hill Companies, Inc. All rights reserved.
2.4 Introducing the Windows Form
Control
2- 19
• The window that is displayed when the
application is running.
• The IDE automatically creates a Windows
Form when you start a new project.
• This form will hold or “contain” other controls.
McGraw-Hill/Irwin
©2002 by The McGraw-Hill Companies, Inc. All rights reserved.
2- 20
2.5 The Button Control
• React to the click of the use
• Perform a task associated with the name of
the button that is displayed on its face.
McGraw-Hill/Irwin
©2002 by The McGraw-Hill Companies, Inc. All rights reserved.
2- 21
Appearance and Use
• Appears as a rectangular-shaped control on
a form.
• Its face can display text, an image, or both.
• The face of the button should clearly indicate
its function.
McGraw-Hill/Irwin
©2002 by The McGraw-Hill Companies, Inc. All rights reserved.
2- 22
Properties
• The most common properties of the Button
control are listed.
ã Most properties are available for every
control.
McGraw-Hill/Irwin
â2002 by The McGraw-Hill Companies, Inc. All rights reserved.
Common Properties of the Button
Control
ã
ã
ã
ã
ã
ã
ã
Name
BackColor
BackgroundImage
Enabled
Font
ForeColor
Image
McGraw-Hill/Irwin
ã
ã
ã
ã
ã
ã
2- 23
ImageAlign
TabIndex
TabStop
Text
TextAlign
Visible
â2002 by The McGraw-Hill Companies, Inc. All rights reserved.
2- 24
Events
• Components are able to respond to events.
• The click event is generated when the user
clicks the mouse button.
• You write code to handle events.
• Double-click the Button control to
automatically open the code window.
McGraw-Hill/Irwin
©2002 by The McGraw-Hill Companies, Inc. All rights reserved.
2- 25
2.6 The Label Control
• Used to display information to the user.
• Used to label other controls or show results
of a calculation.
– Ex. Check box and radio button labels.
McGraw-Hill/Irwin
©2002 by The McGraw-Hill Companies, Inc. All rights reserved.