t u t o r i a l 2009 pearson education, inc. all rights reserved. 1 2 welcome application...
TRANSCRIPT
T U T O R I A L
2009 Pearson Education, Inc. All rights reserved.
1
2Welcome Application
Introducing the Visual Basic2008 Express Edition IDE
2009 Pearson Education, Inc. All rights reserved.
2
Outline
2.1 Test-Driving the Welcome Application
2.2 Overview of the Visual Basic 2008 Express Edition IDE
2.3 Creating a Project for the Welcome Application
2.4 Menu Bar and Toolbar
2.5 Visual Basic 2008 Express Edition IDE Windows
2.6 Auto-Hide
2.7 Using Help
2.8 Saving and Closing Projects in Visual Basic
2009 Pearson Education, Inc. All rights reserved.
3
In this tutorial you will learn: ■ Navigate Visual Studio 2008’s Start Page.■ Create a Visual Basic project.■ Use the IDE’s menus and toolbars.■ Manipulate windows in the Visual Basic 2008
Express Edition IDE.■ Use the auto-hide feature.■ Use the Visual Basic 2008 Express Edition IDE’s
help features.■ Close a Visual Basic project.
Objectives
2009 Pearson Education, Inc. All rights reserved.
4
■ Visual Studio® 2008 is Microsoft’s integrated development environment (IDE) for creating, running and debugging applications.
■ The IDE allows you to create applications by dragging and dropping existing building blocks into place.
■ This technique is called visual programming.
Introduction
Application Requirements
2009 Pearson Education, Inc. All rights reserved.
5
2.1 Test-Driving the Welcome Application
A software company (Deitel & Associates) has asked you to develop a Visual Basic application that displays the message “Welcome to Visual Basic 2008!” and a picture of the company’s bug mascot.
2009 Pearson Education, Inc. All rights reserved.
6
Test-Driving the Welcome Application
■ Open Windows Explorer and navigate to the C:\Examples\Tutorial02 directory (Fig. 2.1).
Contents ofC:\Examples\
Tutorial02
Figure 2.1 | Contents of C:\Examples\Tutorial02.
2009 Pearson Education, Inc. All rights reserved.
7
■ Double click Welcome.exe (Fig. 2.1) to run the application (Fig. 2.2).
Figure 2.2 | Welcome application executing.
Close box
■ Close your running application by clicking its close box,
Test-Driving the Welcome Application (Cont.)
2009 Pearson Education, Inc. All rights reserved.
8
■ Many versions of Visual Studio are available. The examples in this book are based on the Microsoft Visual Basic 2008 Express Edition.
■ You can also purchase a full version of Visual Studio 2008, which includes support for other languages such as Visual C# and Visual C++.
■ To start the IDE, select Start > All Programs > Microsoft Visual Basic 2008 Express Edition.
2.2 Overview of the Visual Basic2008 Express Edition IDE
2009 Pearson Education, Inc. All rights reserved.
9
■ Once the Express Edition begins execution, the Start Page displays (Fig. 2.3).
Figure 2.3 | Start Page in Visual Basic 2008 Express Edition with an empty project list.
Empty Solution Explorer (no projects open)
■ The Start Page contains a list of links to resources in theIDE and on the Internet.
2.2 Overview of the Visual Basic2008 Express Edition IDE (Cont.)
Start Page
Start Page links
2009 Pearson Education, Inc. All rights reserved.
10
■ The Start Page links are organized into sections:– the Recent Projects section
– the Getting Started section, which focuses on usingthe IDE for creating programs, learning Visual Basic, connecting to the Visual Basic developer community and providing development tools
– and the Visual Basic Express Headlines and MSDN: Visual Basic Express Edition sections, which provide links to information about programming in Visual Basic.
■ You can browse the MSDN (Microsoft Developer Network) online library at msdn2.microsoft.com/library.
2.2 Overview of the Visual Basic2008 Express Edition IDE (Cont.)
2009 Pearson Education, Inc. All rights reserved.
11
■ You can also browse the web from the IDE using the internal web browser.
■ To request a web page, type its URL into the location bar (Fig. 2.4) (If the location bar is not already displayed, select View > Other Windows > Web Browser).
2.2 Overview of the Visual Basic2008 Express Edition IDE (Cont.)
2009 Pearson Education, Inc. All rights reserved.
12
Figure 2.4 | Displaying a web page in the Visual Basic 2008 Express Edition IDE.
Selected tab forrequested web page
2.2 Overview of the Visual Basic2008 Express Edition IDE (Cont.)
Requested web page (URL in location-bar drop-down menu)
2009 Pearson Education, Inc. All rights reserved.
13
■ Visual Basic organizes applications into projects and solutions.
– A project is a group of related files, such as codeand images that might make up a program.
– Solutions contain one or more projects.
2.3 Creating a Project for theWelcome Application
2009 Pearson Education, Inc. All rights reserved.
14
■ There are several ways to create a new project or open an existing one:
– Select either File > New Project…, which creates a new project, or File > Open Project…, which opens an existing project.
– From the Start Page, under the Recent Projects section, click the link Create: Project… or Open: Project….
– Click either the New Project Button (Fig. 2.5) or the Open File Button (Fig. 2.5).
Creating a Project for theWelcome Application
2009 Pearson Education, Inc. All rights reserved.
15
Figure 2.5 | New Project button and Recent Projects listing.
Creating a Project for theWelcome Application (Cont.)
Title bar
New Project button
Open File button
Recent Projects listing
2009 Pearson Education, Inc. All rights reserved.
16
Figure 2.6 | New Project dialog.
Creating a Project for theWelcome Application (Cont.)
■ Visual Basic provides templates for a variety of projects (Fig. 2.6). Templates are the project types you can createin Visual Basic.
■ Select Windows Forms Application.
Default projectname (providedby Visual Basic)
2009 Pearson Education, Inc. All rights reserved.
17
Figure 2.7 | New Project dialog with updated project information.
Creating a Project for theWelcome Application (Cont.)
■ To rename the project, type Welcome in the Name: TextBox (Fig. 2.7). Then click OK.
Visual BasicWindows Forms
Application(selected)
Updated project name
2009 Pearson Education, Inc. All rights reserved.
18
Figure 2.8 | Save Project dialog.
Creating a Project for theWelcome Application (Cont.)
■ Save this project in your C:\SimplyVB2008 directory.To change the project’s location, select File > Save All (Fig. 2.8).
2009 Pearson Education, Inc. All rights reserved.
19
Figure 2.9 | Project Location dialog.
Creating a Project for theWelcome Application (Cont.)
■ Use the Browse… Button to locate your SimplyVB2008 directory (Fig. 2.9). After providing the project’s name and location in the Save Project dialog, click Save.
SimplyVB2008 directory(selected)
Select FolderButton
2009 Pearson Education, Inc. All rights reserved.
20Creating a Project for the
Welcome Application (Cont.)
■ The name of each open file is listed on a tab.■ To view a file, click its tab (Fig. 2.10).
Figure 2.10 | Design view of the IDE. Properties window
Menu bar
Active tab
Form (Windows application)
titled Form1
Solution Explorer
Tabs
2009 Pearson Education, Inc. All rights reserved.
21Creating a Project for the
Welcome Application (Cont.)
■ The content of the Form1.vb [Design] tab is the Windows Form Designer.
■ The Form (titled Form1) represents the main window of the Windows Forms application.
2009 Pearson Education, Inc. All rights reserved.
22Creating a Project for the
Welcome Application (Cont.)
■ GUI controls aid both in data entry by users and in formatting and presenting data outputs to users.
■ For example, Internet Explorer (Fig. 2.11) displays web pages requested by users.
2009 Pearson Education, Inc. All rights reserved.
23
Figure 2.11 | Internet Explorer window with GUI controls labeled.(Web site content courtesy of Deitel & Associates, Inc.)
Creating a Project for theWelcome Application (Cont.)
Title bar (Label)
Menu barToolbar
Web site requestedby the user
Menu (Help) ComboBoxDrop-down arrow
Button (displaying an icon)
2009 Pearson Education, Inc. All rights reserved.
24
Figure 2.12 | Visual Basic 2008 IDE menu bar.
2.4 Menu Bar and Toolbar
■ Menus contain commands for managing the IDE and for developing and executing applications.
■ The set of menus displayed (Fig. 2.12) depends on what you are currently doing in the IDE.
2009 Pearson Education, Inc. All rights reserved.
25
Figure 2.13 | Visual Basic IDE menu summary.
2.4 Menu Bar and Toolbar (Cont.)
■ Each menu has a group of related commands (also called menu items) that cause the IDE to perform specific actions (Fig. 2.13).
Menu Description
File Contains commands for opening, closing, adding and saving projects, as well as printing project data and exiting Visual Studio.
Edit Contains editing commands, such as Cut, Paste and Undo.
View Contains commands for displaying IDE windows and toolbars.
Project Contains commands for managing projects and their files.
Build Contains commands for compiling Visual Basic applications.
Debug Contains commands for debugging and running applications.
Data Contains commands for interacting with databases.
Format Contains commands for aligning and modifying a Form’s controls. This menu appears only when a GUI component is selected in Design view.
Tools Contains commands for accessing additional IDE tools and options that enable customization of the IDE.
Window Contains commands for hiding, opening, closing and displaying IDE windows.
Help Contains commands for accessing the IDE’s help features.
2009 Pearson Education, Inc. All rights reserved.
26
2.4 Menu Bar and Toolbar (Cont.)
■ You can access many common commands from the IDE toolbar (Fig. 2.14).
– The toolbar contains icons that graphically represent commands.
– To execute a command via the IDE toolbar, simplyclick its icon.
Figure 2.14 | IDE toolbar.
Down arrow indicates additional commands
are available
Keyboard shortcuts
Toolbar icon indicates a command to open a project
Toolbar
2009 Pearson Education, Inc. All rights reserved.
27
Figure 2.15 | Tooltip demonstration.
■ Positioning the mouse pointer over an icon highlights it and, after a brief pause, displays a description of the icon called a tooltip (Fig. 2.15).
2.4 Menu Bar and Toolbar (Cont.)
Tooltip displayedwhen the mouse
pointer has restedon the icon for a
few seconds
2009 Pearson Education, Inc. All rights reserved.
28
Figure 2.16 | Toolbar icons for four Visual Basic IDE windows.
■ The IDE provides windows for accessing project filesand for customizing forms and controls.
■ You can access these windows by using the IDE toolbar icons (Fig. 2.16) or by selecting the window name, using the View menu.
2.5 Visual Basic 2008 ExpressEdition IDE Windows
Properties icon Object Browser icon
Toolbox icon Solution Explorer icon
2009 Pearson Education, Inc. All rights reserved.
29
Figure 2.17 | Solution Explorer with an open project.
Solution Explorer■ The Solution Explorer window (Fig. 2.17) displays a list of
the files in a project and the projects in a solution.
■ If the Solution Explorer window is not shown in the IDE, you can display it by selecting View > Solution Explorer.
2.5 Visual Basic 2008 ExpressEdition IDE Windows (Cont.)
Propertieswindow icon
Show All Files icon
Form file
Toolbar
Project name
2009 Pearson Education, Inc. All rights reserved.
30
Figure 2.18 | Using the Show All Files icon to display all the files in a solution.
■ Click the Show All Files icon (Fig. 2.18) to display all the files in the solution.
2.5 Visual Basic 2008 ExpressEdition IDE Windows (Cont.)
Collapsed node (plus box expands node to show
related files when clicked)
■ For your single-project solution, Welcome is the only project. The Form file is named Form1.vb.
2009 Pearson Education, Inc. All rights reserved.
31
Figure 2.19 | Expanded node.
■ After clicking the Show All Files icon, click the plus box to the left of the My Project folder (Fig. 2.19) to expand the node.
Navigating a Project with theSolution Explorer
Expanded node (minus box)
2009 Pearson Education, Inc. All rights reserved.
32
■ After clicking the Show All Files icon, click the plus box to the left of the My Project folder (Fig. 2.19) to expand the node.
Navigating a Project with theSolution Explorer (Cont.)
Figure 2.20 | Collapsed node.
Collapsed node (plus box)
2009 Pearson Education, Inc. All rights reserved.
33Navigating a Project with theSolution Explorer (Cont.)
Figure 2.21 | Toolbox displaying the contents of the Common Controls tab.
Group names
Controls
Additional groupnames
Toolbox■ Using visual programming, you can
“drag and drop” controls onto the Form.
■ If the Toolbox is not visible, select View > Toolbox.
■ The Toolbox (Fig. 2.21) groups controls into categories.
2009 Pearson Education, Inc. All rights reserved.
34
Properties Window■ The Properties window (Fig. 2.22) displays an object’s
attributes, such as its size, color and position.■ The Properties window allows you to set object
properties visually without writing code.■ If the Properties window is not visible, select
View > Properties Window (or press F4).
Navigating a Project with theSolution Explorer (Cont.)
2009 Pearson Education, Inc. All rights reserved.
35Navigating a Project with theSolution Explorer (Cont.)
Figure 2.22 | Properties window displaying a Form’s properties.
Object’sname
(Form1) Object’s class
(System.Windows.Forms.Form)
Down arrow for selecting Formor control objects
Toolbar
Items that have beenchanged from their defaultvalues (by the user or by VisualStudio) are listed in bold
Scrollbox
Scrollbar
Property values(right column)
Properties(left column)
Description ofselected property
Design category
Selected property
Alphabetical icon
Categorized icon
Component object box
2009 Pearson Education, Inc. All rights reserved.
36
■ At the top of the Properties window is the component object box, which displays each object’s name and class type.
■ Icons on the toolbar sort the properties either alphabeticallyor categorically.
■ Each gray horizontal bar to the left of the scrollbar is a category that groups related properties.
■ The left column of the Properties window lists the object’s property names; the right column displays each property’s value.
■ Whenever you select a property, a description of the property displays at the bottom of the Properties window.
Navigating a Project with theSolution Explorer (Cont.)
2009 Pearson Education, Inc. All rights reserved.
37
■ Auto-hide is enabled by clicking the window’s verticalpin icon.
■ The toolbar along one of the edges of the IDE containsone or more tabs, each of which identifies a hiddenwindow (Fig. 2.23) and displays the window whenclicked (Fig. 2.24).
Using Auto-Hide
Figure 2.23 | Hidden-window tabs.
Tab for hidden window
Figure 2.24 | Displaying a hidden window with auto-hide enabled.
Mouse pointer over the
tab for the Toolbox Horizontal pin icon (auto-hide enabled)
Toolbox is displayedwhen the mouse pointeris placed on the tab forthe Toolbox
Title bar
2009 Pearson Education, Inc. All rights reserved.
38
■ Move the mouse pointer outside the Toolbox window’s area to hide the Toolbox (Fig. 2.25).
Figure 2.25 | Hiding the Toolbox by moving the mouse pointeroutside of the Toolbox’s area.
Mouse pointer over the tab for the Toolbox
(Toolbox window is hidden)
Using Auto-Hide (Cont.)
2009 Pearson Education, Inc. All rights reserved.
39
■ To disable auto-hide click the pin icon in the title bar.■ When a window is “pinned down,” the pin icon is
vertical (Fig. 2.26)■ When auto-hide is enabled, the pin icon is horizontal.
Figure 2.26 | Pin icon in vertical position.
Vertical pin icon(auto-hide is disabled)
Using Auto-Hide (Cont.)
2009 Pearson Education, Inc. All rights reserved.
40
■ Help provides a list of articles pertaining to the “current content.”
■ The help window also provides help topics, code samples and “Getting Started” information (Fig. 2.27).
Figure 2.27 | Help menu commands.
Command Description
How Do I? Contains links to relevant topics, including how to upgrade applications and learn more about web services, architecture and design, files, data and more.
Search Finds help articles based on search keywords.
I ndex Displays an alphabetized list of topics which you can browse.
Contents Displays a categorized table of contents in which help articles are organized by topic.
Using Auto-Hide (Cont.)
2009 Pearson Education, Inc. All rights reserved.
41
■ Visual Basic also provides context-sensitive help, which displays relevant help articles (Fig. 2.28).
■ To use context-sensitive help, click an item,then press the F1 key.
Using Auto-Hide (Cont.)
2009 Pearson Education, Inc. All rights reserved.
42
Figure 2.28 | Context-sensitive help window.
Using Auto-Hide (Cont.)
Selected item(Windows form)
Relevant helparticle
Context-sensitivehelp window
HowDo I Search Index Contents
Toolbar
2009 Pearson Education, Inc. All rights reserved.
43
Once you’re finished with a project, you shouldsave the project’s files and close the project.■ Before closing the project for the Welcome application, you should save its files, ensuring
that any changes made to the project are not lost.■ Although you did not make any changes, save your project files by selecting File > Save All.■ Select File > Close Project.
2.8 Saving and Closing Projectsin Visual Basic