Welcome to Microsoft Visual Basic 2005 Step by Step, a comprehensive introduction to Visual Basic programming using the Microsoft Visual Basic 2005 software.. By using this book, you'll
Trang 2www.microsoft.com/learning/books/ Send comments to
mspinput@microsoft.com
Microsoft, Microsoft, ActiveX, DataTips, Excel, FrontPage, IntelliSense,Microsoft Press, MSDN, MS-DOS, Outlook, PowerPoint, Visual Basic,Visual C#, Visual C++, Visual InterDev, Visual J#, Visual J++, Visual
Studio, Visual Web Developer, Windows, Windows NT, and Windows
Server are either registered trademarks or trademarks of Microsoft
Corporation in the United States and/or other countries Other product andcompany names mentioned herein may be the trademarks of their respectiveowners
The example companies, organizations, products, domain names, e-mailaddresses, logos, people, places, and events depicted herein are fictitious No
Trang 3association with any real company, organization, product, domain name, e-This book expresses the author's views and opinions The information
contained in this book is provided without any express, statutory, or impliedwarranties Neither the authors, Microsoft Corporation, nor its resellers, ordistributors will be held liable for any damages caused or alleged to becaused either directly or indirectly by this book
Acquisitions Editor: Ben Ryan
Project Editor: Melissa von Tschudi-Sutton
Production: Online Training Solutions, Inc.
Body Part No X11-44966
Trang 4This title includes references to electronic content, such as sample files,sample code, beta software, tools, and other content This content is
provided as an additional learning tool to accompany the text Although thereferences to this content might mention a CD or CD-ROM where these filesare available, you can access selected portions of this content online bygoing to http://www.microsoft.com/mspress/products/mell
To view the companion content for a title at this Web site, type in the
product ISBN (International Standard Book Number) of the title in the text
box and click Go.
The ISBN for this title is listed below and can also be found on the LOC(Library of Congress) page listed in the Table of Contents
ISBN: 0-7356-2131-4
Trang 5Welcome to Microsoft Visual Basic 2005 Step by Step, a comprehensive
introduction to Visual Basic programming using the Microsoft Visual Basic
2005 software I've designed this practical, hands-on tutorial with a variety ofskill levels in mind The result is that new programmers can learn softwaredevelopment fundamentals in the context of useful, real-world applications,and experienced Visual Basic programmers can quickly master the essentialtools and programming techniques offered in the Visual Basic 2005 upgrade
Complementing this comprehensive approach is the book's structure—4topically organized parts, 20 chapters, and 54 step-by-step exercises andsample programs By using this book, you'll quickly learn how to createprofessional-quality Visual Basic 2005 applications for the Microsoft
Windows operating system and a variety of Web browsers You'll also havefun!
Trang 6Visual Basic 2005 is a development tool that you can use to build
applications that perform useful work and look great within a variety ofsettings Using Visual Basic 2005, you can create applications for the
Windows operating system, the Web, hand-held devices, and a host of otherenvironments and settings The most important advantage of Visual Basic isthat it has been designed to increase productivity in your daily developmentwork—especially if you need to use information in databases or create
solutions for the Internet—but an important additional benefit is that onceyou become comfortable with the development environment in MicrosoftVisual Studio 2005, you can use the same tools to write programs for
Microsoft Visual C++ 2005, Microsoft Visual C# 2005, Microsoft Visual J#
2005, and other third-party tools and compilers
Visual Basic NET Versions
The first version of Visual Basic NET (Microsoft Visual Basic NET 2002)was released in February 2002 The second release (Microsoft Visual Basic.NET 2003) was widely available in March 2003 After a long period ofdevelopment and integration work, Microsoft released Visual Basic 2005 inlate 2005 Visual Basic 2005 is now so tightly integrated with Visual Studiothat it is only available as a component in the Visual Studio 2005
programming suite, which includes the Visual C#, Visual C++, and Visual J#compilers and other Microsoft NET development tools However, VisualStudio 2005 is sold in several different product configurations, includingStandard Edition, Professional Edition, Team Suite, and Express Edition.I've written this book to be compatible with all editions of Visual Basic 2005and Visual Studio 2005, but especially with the tools and techniques
available in Visual Studio Standard Edition and Visual Studio ProfessionalEdition Although Visual Basic 2005 is similar in many ways to Visual Basic.NET 2003, there are many important differences and improvements, so Irecommend that you complete the exercises in this book using the VisualBasic 2005 software
NOTE
Trang 7
2005 software (sold separately) for use
Trang 8This book is designed to help you build skills in a number of essential areas.You can use this book if you're new to programming, switching from anotherprogramming language, or upgrading from Visual Basic 6 or Visual Basic.NET 2003 Use the following table to find your best starting point in thisbook
Trang 93 Pay special attention to the “Upgrade Notes: MigratingVisual Basic 6 Code to Visual Basic 2005” sidebarsnear the beginning of each chapter, which highlight thesignificant differences between Visual Basic 6 andVisual Basic 2005
4 Skim Chapters 5 through 13 to review thefundamentals of event-driven programming, usingvariables, and writing decision structures Give specialattention to Chapters 5, 6, 9, and 12
5 Work sequentially from Chapters 14 through 20 tolearn the new Visual Basic 2005 features related touser interface design, database programming, and Webprogramming
2 Use the Upgrading Index to see a list of the newfeatures in Visual Basic 2005 and how Visual Basic 6program code should be upgraded
3 Read the Quick Reference at the end of each chapterfor a brief review of the major tasks in the chapter TheQuick Reference topics are listed in the same order asthey're presented in the chapter
Trang 10You'll need the following hardware and software to complete the exercises inthis book:
Microsoft Windows XP Professional Edition with Service Pack 2 orMicrosoft Windows XP Home Edition with Service Pack 2, MicrosoftWindows Server 2003 with Service Pack 1, or Microsoft Windows
2000 with Service Pack 4 (Microsoft Windows 2000 Datacenter Server
is not supported)
Microsoft Visual Studio 2005 Standard Edition or Microsoft VisualStudio 2005 Professional Edition
600 MHz Pentium or compatible processor (1 GHz Pentium
recommended)
192 MB RAM (256 MB or more recommended)
Video (800 x 600 or higher resolution) monitor with at least 256 colors(1024 x 768 High Color 16-bit recommended)
Trang 11This book was reviewed and tested against the August 2005 CommunityTechnical Preview (CTP) of Visual Studio 2005 The August CTP was thelast preview before the final release of Visual Studio 2005 This book isexpected to be fully compatible with the final release of Visual Studio 2005and Visual Basic 2005 If there are any changes or corrections for this book,they will be collected and added to an easy-to-access Microsoft KnowledgeBase article on the Web See the “Support for This Book” section for moreinformation
Trang 12The CD-ROM inside this book contains the practice files that you'll use asyou perform the exercises in the book For example, when you're learning
how to display database tables on a form by using the GridDataView control,
you'll open one of the practice files—an academic database named
Students.mdb—and then use Visual Studio database programming tools toaccess the database By using the practice files, you won't waste time
creating files that aren't relevant to the exercise Instead, you can concentrate
on learning how to master Visual Basic 2005 programming techniques Withthe files and the step-by-step instructions in the chapters, you'll also learn bydoing, which is an easy and effective way to acquire and remember newskills
IMPORTANT
Before you break the seal on the CD-ROM, be sure that this book matchesyour version of the software This book is designed for use with Visual
Studio 2005 and the Visual Basic 2005 programming language To find outwhat software you're running, you can check the product package, or youcan start the software, open a project, and then click About Microsoft VisualStudio on the Help menu at the top of the screen
Installing the Practice Files
Installing the practice files on your hard disk requires approximately 7.2 MB
of disk space Follow these steps to install the practice files on your
computer's hard disk so that you can use them with the exercises in thisbook
1 Remove the CD from the package inside this book, and insert it intoyour CD-ROM drive
NOTE
An end user license agreement should open automatically If this
agreement does not appear, open My Computer on the desktop or Startmenu, double-click the icon for your CD-ROM drive, and then double-click StartCD.exe
Trang 132 Review the end user license agreement If you accept the terms, selectthe accept option, and then click Next.
in several practice files to locate essential components, such as artworkand database files, when you use them
5 When the files have been installed, remove the CD-ROM from yourdrive and replace it in the package inside the back cover of your book
If you accepted the default settings, a folder named c:\vb05sbs has beencreated on your hard disk, and the practice files have been placed in thatfolder You'll find one folder in c:\vb05sbs for each chapter in the book.(Some of the files represent completed projects, and others will requirethat you enter some program code.) If you have trouble running any ofthe practice files, refer to the text in the book that describes those files
Using the Practice Files
Each chapter in this book explains when and how to use the practice files forthat chapter When it's time to use a practice file, the book lists instructionsfor how to open the file The chapters are built around scenarios that
simulate real programming projects so that you can easily apply the skillsyou learn to your own work
NOTE
Visual Basic 2005 features a new file format for its projects and solutions.Accordingly, you won't be able to open the practice files for this book ifyou're using an older version of the Visual Basic or Visual Studio software
To see what version of Visual Basic or Visual Studio you're using, click the
Trang 14Visual Studio is extremely customizable and can be configured to open andsave projects and solutions in different ways The instructions in this bookgenerally rely on the default setting for Visual Studio For more informationabout how settings within the development environment affect how youwrite programs and use the practice files, see the section “Customizing IDESettings to Match Step by Step Exercises” in Chapter 1, “Exploring theVisual Studio Integrated Development Environment.”
For those of you who like to know all the details, here's a list of the VisualBasic projects included on the CD-ROM Each project is located in its ownfolder and has several support files Look at all the things you will be doing!
Trang 16Handler
A project with a completed error handler for loading filesthat demonstrates the Try…Catch syntax
control to give the user visual feedback during long sorts.Dynamic
Trang 17Quick Note A simple note-taking utility that demonstrates the
FileOpen function and the TextBox, MenuStrip, and SaveFileDialog controls.
Sort Text A text file editor with a menu bar that demonstrates how to
manage Open, Close, Save As, Insert Date, Sort Text, and
Exit commands in a program Contains a ShellSort module
for sorting arrays that can be added to other programmingprojects
Text Browser Displays the contents of a text file in a Visual Basic
program Demonstrates menu commands, a Try…Catch
error handler, and the FileOpen and LineInput functions,
and serves as a foundation for the other programs in thischapter
Chapter 14
Add Controls Demonstrates how controls are added to a Windows Form
at run time by using program code (not the Designer).Anchor and
Lucky Seven
Help
The enhanced Lucky7 program (TrackWins) from Chapter
10, which is enhanced again through the addition of asecond form to display Help information
Chapter 15
Trang 18Draw Shapes Demonstrates a few of the useful graphics methods in the
System.Drawing namespace, including DrawEllipse, FillRectangle, and DrawCurve.
Moving Icon Animates an icon on the form, moving it from the top of
the form to the bottom each time that you click the MoveDown button
Person Class Demonstrates how to create new classes, properties, and
methods in a Visual Basic project The new Person class is
an employee record with first name, last name, and date ofbirth fields, and it contains a method that computes thecurrent age of an employee
using an error handler, the Print method, and the DrawImage method.
Print Text Demonstrates how simple text is printed in a Visual Basic
program
Chapter 18
ADO Form Demonstrates how ADO.NET is used to establish a
Trang 19interconnected and bound to objects on a form
Chapter 20
Chap20 Demonstrates using Visual Web Developer and ASP.NET
to create a car loan calculator that runs in a Web browser,offers Help information, and displays database records
Trang 203 Click Remove.
4 Follow the onscreen instructions to remove the practice files
Trang 21Before you start the exercises in this book, you can save time by
understanding how I provide instructions and the elements I use to
communicate information about Visual Basic programming The followinglists identify stylistic conventions, discuss helpful features of the book, andpoint out a few elements that are especially useful for readers who plan toupgrade Visual Basic 6 applications to Visual Basic 2005
Conventions
The names of all program elements—controls, objects, methods,
functions, properties, and so on—appear in italic
Hands-on exercises for you to follow are given in numbered lists ofsteps (1, 2, and so on) A round bullet (●) indicates an exercise that hasonly one step
Text that you need to type appears in bold
As you work through steps, you'll occasionally see tables with lists ofproperties that you'll set in Visual Studio Text properties appear withinquotes, but you don't need to type the quotes
A plus sign (+) between two key names means that you must pressthose keys at the same time For example, “Press Alt+Tab” means thatyou hold down the Alt key while you press Tab
Elements labeled Note, Tip, More Info, or Important provide additionalinformation or alternative methods for a step You should read thesebefore continuing with the exercise
Other Features
You can learn special programming techniques, background
information, or features related to the information being discussed byreading the sidebars that appear throughout the chapters These sidebarsoften highlight difficult terminology or suggest future areas for
Trang 22a basic overview, or executive summary, of the features in Visual Basic
2005 for Visual Basic 6 users Use these sidebars if you're interested inhow Visual Basic has changed in the context of an individual topic,such as variable declaration, Toolbox controls, or database
programming (Readers upgrading from Visual Basic NET 2002 or
2003 to Visual Basic 2005 are welcome to review these notes as well,but moving to Visual Basic 2005 will be easier for you.)
Trang 23You are invited to check out the following links that provide support for theVisual Studio 2005 software and this book's contents:
Visual Studio 2005 Software Support
For questions about the Visual Studio 2005 software, I recommend twoMicrosoft Web sites:
Online Companion Content
The online companion content page has content and links related to thisbook, including a link to the Microsoft Press Technology Updates Web page.(As technologies related to this book are updated, links to additional
information will be added to the Microsoft Press Technology Updates Webpage Visit the page periodically for updates on Visual Studio 2005 and othertechnologies.) The online companion content page for this book can be
found at:
http://www.microsoft.com/mspress/companion/0-7356-2131-4/
Microsoft Press Web Site
The Microsoft Press Web site has descriptions for the complete line of
Trang 24http://www.microsoft.com/learning/books/
Trang 25Every effort has been made to ensure the accuracy of this book and the
contents of the CD As corrections or changes are collected, they will beadded to a Microsoft Knowledge Base article on the Web To view the list ofknown corrections for this book, visit the following Web site:
http://support.microsoft.com/kb/905036/
In addition, Microsoft Press provides general support information for itsbooks and companion CDs at the following Web site:
http://www.microsoft.com/learning/support/books/
Questions and Comments
If you have comments or questions that are not answered by visiting the sitesabove, please send them to Microsoft Press via e-mail to
Trang 26Getting Started with Microsoft Visual Basic 2005
Trang 27Exploring the Visual Studio Integrated Development Environment
Save your changes, and exit Visual Studio
Microsoft Visual Basic 2005 is an important upgrade and enhancement of thepopular Visual Basic development system and an iterative upgrade of theMicrosoft Visual Basic NET 2003 software This chapter gives you the skillsyou need to quickly and efficiently get up and running with the Visual Studio
2005 Integrated Development Environment (IDE)—the place where you willwrite Visual Basic programs You should read this chapter whether you arenew to Visual Basic programming or you have used previous versions ofVisual Basic or Visual Studio
In this chapter, you'll learn how to start Visual Studio 2005 and how to use theIDE to open and run a simple program You'll learn the essential Visual Studiomenu commands and programming procedures; you'll open and run a simple
Trang 28setting called a property; and you'll practice moving, sizing, docking, and auto
hiding tool windows You'll also learn how to open a Web browser withinVisual Studio, how to get more information by using online Help, and how toexit the development environment and save your changes
Upgrade Notes: Migrating Visual Basic 6 Code to Visual Basic 2005
Microsoft Visual Basic 6.0 has been an extremely successful product
Even though Visual Basic 6 was released in 1998, many software
developers, including a large number of professional programmers whowork outside of North America, continue to use this tool to develop andmodify applications for Microsoft Windows If you are thinking aboutupgrading to Visual Basic 2005 but are most comfortable with the
commands and features in Visual Basic 6, there are some important
product features and migration tips that you should be aware of To helpprogrammers who are moving from Visual Basic 6, I plan to start eachchapter of this book with a sidebar that highlights the feature changes
that you should be aware of (If you are not upgrading from Visual Basic
6, simply skip the sidebar.)
Remember that you don't need any programming experience to learn
Visual Basic 2005 using this book But if you have some Visual Basic 6knowledge already, you will benefit from an executive summary spellingout the differences So to begin with, here is my list of upgrade notes forChapter 1:
Visual Basic is now a full member of Visual Studio—it shares theVisual Studio development environment with Microsoft Visual C++
Trang 29The Visual Studio development environment contains several newand modified programming tools The Project window is now calledSolution Explorer, and help information is delivered through a newtool called Microsoft Document Explorer You'll find that the
Toolbox has changed quite a bit—it's now subdivided into severalfunctional categories, such as Common Controls, Components, andData
Most of the programming tool windows (including the Toolbox)have an auto hide feature that hides the tool as a tab when it isn'tneeded Auto hiding tools saves you design and coding space withinthe development environment
Projects are now saved in a different way You give your project a
name before you create it, and the files that you create remain in
memory for testing and debugging until you choose to save (ordiscard) them The project itself is spread over several files andfolders—even more than in Visual Basic 6 In Visual Basic 6,
programs that are made up of multiple projects are called project groups; now they're called solutions.
To upgrade Visual Basic 6 applications to Visual Basic 2005, youcan use a tool called the Visual Basic Upgrade Wizard, which startsautomatically when you open a Visual Basic 6 program in VisualStudio The Upgrade Wizard isn't a complete solution for migratingVisual Basic 6 applications However, the wizard efficiently handlesmost repetitive code changes and can even swap Visual Basic 6controls for Visual Studio 2005 controls on forms In addition to thisupgrade tool, which prepares a complete migration report, you canalso use the Upgrade Visual Basic 6 command on the Visual StudioTools menu to quickly translate a line of Visual Basic 6 code andinsert it into a Visual Basic 2005 project
If you open Visual Basic NET 2002 or 2003 projects in VisualStudio 2005, they are converted automatically via the Visual StudioConversion Wizard
Trang 31Although the programming language you'll be learning in this book is VisualBasic, the development environment you'll be using to write programs iscalled the Microsoft Visual Studio Integrated Development Environment, orIDE for short Visual Studio is a powerful and customizable programmingworkshop that contains all the tools you need to build robust programs forWindows and the Web quickly and efficiently Most of the features in theVisual Studio IDE apply equally to Visual Basic, Visual C++, Visual C#, andVisual J# Use the following procedures to start Visual Studio now
IMPORTANT
If you haven't yet installed this book's practice files, work through “FindingYour Best Starting Point” and “About the CD-ROM and Practice Files” inthis book's Introduction (I recommend that you place the project files andrelated subfolders in the c:\vb05sbs folder.) Then return to this chapter
Start Visual Studio 2005
1 On the Windows taskbar, click Start, point to All Programs, and thenpoint to the Microsoft Visual Studio 2005 folder
as well If this is the case, you'll be able to follow the procedures in thisbook without difficulty, but you will also have access to some cooladvanced features and capabilities However, even though it is
tempting, don't try to use this book if you have an earlier version of theVisual Basic software If that's your situation, you'll be better served bylocating an earlier (and perhaps lower priced!) edition of my book, such
Trang 32describes the Visual Basic NET 2003 software) or Microsoft Visual Basic Professional 6.0 Step by Step (which describes the Visual Basic 6
software)
2 Click the Microsoft Visual Studio 2005 icon
Visual Studio starts, and you see the development environment on thescreen with its many menus, tools, and component windows (These
windows are sometimes called tool windows.) You also should see a
Start Page containing a set of links, MSDN articles, and project options
In Visual Studio 2005, the Start Page is much improved and has
become a comprehensive source of information about your project, aswell as resources within the Visual Basic development community Thenew Community menu on the Visual Studio menu bar provides access
to many of the same resources
The first thing most developers do when they start Visual Studio is open anexisting project—either a completed solution they want to work with again
Trang 33Open a Visual Basic project
1 Click the Open Projects/Solutions link in the Start Page
The Open Project dialog box appears on the screen with several
options (You can also display this dialog box by clicking the OpenProject command on the File menu or by pressing Ctrl+O.) Even if youhaven't used Visual Studio before, the Open Project dialog box willseem straightforward because it resembles the familiar Open dialog box
in Microsoft Word or Microsoft Excel
TIP
In the Open Project dialog box, you see a number of shortcut iconsalong the left side of the window The My Projects icon is particularlyuseful; it opens the Projects folder inside the My Documents\VisualStudio 2005 folder on your system By default, Visual Studio savesyour projects in this Projects folder, giving each project its own
subfolder The folder VSMacros80 contains the macro files for VisualStudio 2005 (which is also called Visual Studio version 8.0 in some
Trang 342 Browse to the c:\vb05sbs folder on your hard disk
The c:\vb05sbs folder is the default location for this book's extensivesample file collection, and you'll find the files there if you followed thesetup instructions in “About the CD-ROM and Practice Files” at thebeginning of this book If you didn't install the sample files, close thisdialog box and install them now by using the CD-ROM included withthis book Then return to this procedure and continue
3 Open the chap01\musictrivia folder, and then double-click the
MusicTrivia solution file (If your system shows file name extensions,this file will end with sln.)
Visual Studio loads the MusicTrivia form, properties, and program codefor the MusicTrivia solution The Start Page probably is still visible, but
in the upper-right corner of the screen, Solution Explorer lists some ofthe files in the solution
TROUBLESHOOTING
If you see an error message indicating that the project you want to open is in
a newer file format, you might be trying to load Visual Basic 2005 files intothe older Visual Basic NET 2002 or 2003 software (Earlier versions ofVisual Basic cannot open the Visual Basic 2005 projects included on thecompanion CD-ROM.) To check which version of Visual Basic you're using,click the About command on the Help menu
Visual Studio provides a special check box named Always Show Solution tocontrol several options related to solutions within the IDE The check box islocated on the Projects and Solutions/General tab of the Options dialog box,which you open by clicking the Options command on the Tools menu If thecheck box is selected, a subfolder is created for each new solution, placingthe project and its files in a separate folder beneath the solution Also, if youselect the Always Show Solution check box, a few options related to
solutions appear in the IDE, such as commands on the File menu and a
solution entry in Solution Explorer If you like the idea of creating separatefolders for solutions and seeing solution-related commands and settings,select this check box
Trang 35so opening the project file (.vbproj) has the same effect as opening thesolution file (.sln) But for a multi-project solution, you will want toopen the solution file Visual Basic 2005 offers a new file format for itsprojects and solutions, but the basic terminology that you might havelearned while using Visual Basic NET 2002 or 2003 still applies
Trang 36At this point, you should take a few moments to study the Visual Studio IDEand identify some of the programming tools and windows that you'll beusing as you complete this course If you've written Visual Basic programsbefore, you'll recognize many (but probably not all) of the programmingtools Collectively, these features are the components that you use to
construct, organize, and test your Visual Basic programs A few of the
programming tools also help you learn more about the resources on yoursystem, including the larger world of databases and Web site connectionsavailable to you There are also several powerful Help tools
The menu bar provides access to most of the commands that control the
development environment Menus and commands work as they do in allWindows-based programs, and you can access them by using the keyboard
or the mouse Located below the menu bar is the Standard toolbar, a
collection of buttons that serve as shortcuts for executing commands andcontrolling the Visual Studio IDE If you've used Excel or Word, the toolbarshould be a familiar concept To activate a button on the toolbar, use yourmouse to click the button You can see the full list of available toolbars byright-clicking the toolbar in the IDE
Along the bottom of the screen is the Windows taskbar You can use the
taskbar to switch between various Visual Studio components and to activateother Windows-based programs You might also see taskbar icons for
Microsoft Internet Explorer, antivirus utilities, and other programs installed
on your system
The following illustration shows some of the tools and windows in the
Visual Studio IDE Don't worry that this illustration looks different fromyour current development environment view You'll learn more about theseelements (and how you adjust your views) as you work through the chapter
Trang 37developers' preferences are exactly alike, it is difficult to predict what you'llsee if your Visual Studio software has already been used (What I show isessentially the “out of the box” view.)
If a tool isn't visible and you want to see it, click the View menu and selectthe tool Because the View menu has expanded steadily over the years,
Microsoft has moved some of the less frequently used View tools to a
submenu called Other Windows Check there if you don't see what you need
The exact size and shape of the tools and windows depend on how yourdevelopment environment has been configured With Visual Studio, you can
align and attach, or dock, windows to make visible only the elements that you want see You can also partially conceal tools as tabbed documents
Trang 38important to you now and which you can learn about later is a difficult earlychallenge when you're learning the busy Visual Studio interface Your
development environment will probably look best if you set your monitorand Windows desktop settings so that they maximize your screen space, buteven then things can get a little crowded (For example, I'm using a screenresolution of 1024 × 768 for some of the full-size screen shots in this book.You can change the screen resolution by right-clicking the Windows desktopand clicking Properties.)
The purpose of all this tool complexity is to add many new and useful
features to the IDE while providing clever mechanisms for managing theclutter These mechanisms include features such as docking, auto hiding,floating, and a few other window states that I'll describe later If you're juststarting out with Visual Basic, the best way to deal with this feature tension
is to hide the tools that you don't plan to use often to make room for theimportant ones The crucial tools for beginning Visual Basic programming—the ones you'll start using right away in this book—are Solution Explorer,the Properties window, the Designer, and the Toolbox You won't use theServer Explorer, Class View, Resource View, Object Browser, or Debugwindows until later in the book
In the following exercises, you'll start experimenting with the crucial tools inthe Visual Studio IDE You'll also learn how to display a Web browser
within Visual Studio and how to hide the tools that you won't use for a
while
The Designer
If you completed the last exercise, the MusicTrivia project is loaded in theVisual Studio development environment However, the user interface, or
form, for the project might not yet be visible in Visual Studio (More
sophisticated projects might contain several forms, but this simple triviaprogram needs only one.) To make the form of the MusicTrivia project
visible in the IDE, you display it by using Solution Explorer
Display the Designer
Trang 391 Locate the Solution Explorer window near the upper-right corner of theVisual Studio development environment If you don't see SolutionExplorer (if it is hidden as a tab in a location that you cannot see or isn'tcurrently visible), click Solution Explorer on the View menu to displayit.
When the MusicTrivia project is loaded, Solution Explorer looks likethis:
2 Click the MusicTrivia.vb form in the Solution Explorer window
All form files, including this one, have a tiny form icon next to them sothat you can easily identify them When you click the form file, VisualStudio highlights it in Solution Explorer, and some information aboutthe file appears in the Properties window (if it is visible)
3 Click the View Designer button in Solution Explorer to display theprogram's user interface
The MusicTrivia form is displayed in the Designer, as shown here:
Trang 40Now try running a Visual Basic program with Visual Studio
TIP
If you don't see the Start Page and MusicTrivia.vb [Design] tabs, your
development environment might be in Multiple Documents view instead ofTabbed Documents view To change this option, click Options on the Toolsmenu On the left side of the Options dialog box, click the Environmentfolder, and then click General On the right, under Window Layout, click theTabbed Documents option, and then click OK The next time you start
Visual Studio, the various windows that you open have tabs, and you canswitch between them with a simple button click
Running a Visual Basic Program
Music Trivia is a simple Visual Basic program designed to familiarize youwith the programming tools in Visual Studio The form you see now has