Microsoft Visual Basic 2008 Express Edition
Total Page:16
File Type:pdf, Size:1020Kb
PUBLISHED BY Microsoft Press A Division of Microsoft Corporation One Microsoft Way Redmond, Washington 98052-6399 Copyright © 2008 by Microsoft Corporation All rights reserved. No part of the contents of this book may be reproduced or transmitted in any form or by any means without the written permission of the publisher. Library of Congress Control Number: 2008920560 Printed and bound in the United States of America. 1 2 3 4 5 6 7 8 9 QWT 3 2 1 0 9 8 Distributed in Canada by H.B. Fenn and Company Ltd. A CIP catalogue record for this book is available from the British Library. Microsoft Press books are available through booksellers and distributors worldwide. For further information about international editions, contact your local Microsoft Corporation office or contact Microsoft Press International directly at fax (425) 936-7329. Visit our Web site at www.microsoft.com/mspress. Send comments to [email protected]. Microsoft, Microsoft Press, DirectX, Excel, Expression, Expression Blend, IntelliSense, Internet Explorer, Jscript, MSDN, MSN, Outlook, Silverlight, SQL Server, Visual Basic, Visual C#, Visual C++, Visual Studio, Visual Web Developer, Win32, Windows, Windows Live, Windows Mobile, Windows Server, Windows Vista, Xbox and Xbox 360 are either registered trademarks or trademarks of Microsoft Corporation in the United States and/or other countries. Other product and company names mentioned herein may be the trademarks of their respective owners. The example companies, organizations, products, domain names, e-mail addresses, logos, people, places, and events depicted herein are fictitious. No association with any real company, organization, product, domain name, e-mail address, logo, person, place, or event is intended or should be inferred. This book expresses the author’s views and opinions. The information contained in this book is provided without any express, statutory, or implied warranties. Neither the authors, Microsoft Corporation, nor its resellers, or distributors will be held liable for any damages caused or alleged to be caused either directly or indirectly by this book. Acquisitions Editor: Ben Ryan Editorial Production: Happenstance Type O Rama Developmental Editor: Sandra Haynes Technical Reviewer: Richard Triance Project Manager: John Pierce Body Part No. X14-55519 Buy the Book If you enjoyed the eBook and want your own, print edition, please click here to order. Or go to: www.microsoft.com/mspress/books/12282.aspx ISBN 978-0-7356-2541-9 978 0 7356 2541 9 256 pages; Companion DVD Your Next Steps to Learning More about Microsoft® Visual Studio® Developer Step by Step z Hands-on tutorial covering fundamental techniques and features z Practice fi les on CD z Prepares and informs new-to- MicrosoftMi ft MicrosoftMi ft MicrosoftMi ft MicrosoftMi ft Visual Basic® 2008 Visual C#® 2008 ASP.NET 3.5 ADO.NET 2.0 topic programmers Step by Step Step by Step Step by Step Step by Step Michael Halvorson John Sharp George Shepherd Rebecca M. Riordan 978-0-7356-2537-2 978-0-7356-2430-6 978-0-7356-2426-9 978-0-7356-2164-0 Whether you use technology at home, school, or work, fi nd the books you need at: microsoft.com/mspress Contents Chapter 1 Getting Help: Microsoft Visual Studio 2008 Introducing Microsoft Visual Basic 2008 Express Edition Documentation 34 Express Edition 1 Coding Your Console Application 37 Customizing the IDE 39 What Is .NET? 2 Creating a Windows Application 41 What Is Visual Basic 2008? 4 Is Visual Basic 2008 an Object-Oriented Programming Language? 4 Chapter 4 What Is Visual Basic 2008 Express Edition? 9 Creating Your Own Web Browser in Less What Kinds of Applications Can You Build with Than Five Minutes 47 Visual Basic 2008 Express Edition? 10 What Is a Project? 48 What Are the Key Features You Need to Know What Is the Design Layout? 49 About? 11 To Create a Simple Web Browser 50 Putting It All Together 56 Chapter 2 Installing Visual Basic 2008 Express Edition 15 Chapter 5 Preparing to Install Visual Basic 2008 Express Edition 16 Using Rapid Application Development Tools Side-by-Side Installation 16 with Visual Basic 2008 59 Prerelease Versions of Visual Basic 2008 Express Edition 17 Snapping and Aligning Controls Using Snap Lines 60 Installing Visual Basic 2008 Express Edition 17 Using IntelliSense—Your New Best Friend! 62 Using IntelliSense as You Go 62 Chapter 3 Using IntelliSense Filtering: Removing the “Uncommon” 63 Creating Your First Applications 25 Opening IntelliSense: Pressing Ctrl+Spacebar 64 Three Types of Applications: What Are the Differences? 26 Opening IntelliSense: Typing a Period or Left Parenthesis 64 Getting Started with the IDE 28 Using IntelliSense Code Snippets: The Time-Saver 66 Building the Projects 31 Invoking IntelliSense Code Snippets 67 Building a Console Application 31 Exploring Real-Time Error Detection and Correction 68 Getting to Know Solution Explorer 32 Oh, My...My Is Great 70 Contents iii Renaming 72 Using SQL Server 2005 Express Edition in Why Should You Rename? 73 Visual Basic 2008 Express Edition 150 How to Use the Rename Feature 73 Creating a Database Using Visual Basic 2008 Exploring Common Windows Controls 75 Express Edition 151 What Happens When an Event Is Triggered? 78 Creating Tables in Your Database 153 Creating Relationships Between the Tables 155 Chapter 6 Entering Data in SQL Server Tables Using Visual Studio 159 Modifying Your Web Browser 85 What Are ADO.NET, Data Binding, and LINQ? 163 Opening Your Application 86 Developing the CarTracker Application 165 Interacting Through Dialog Boxes 93 Using the Component Tray 172 Adding an About Dialog Box 93 How Do I Get More Meaningful Information Adding a Navigate Dialog Box 96 on My Form? 173 Having a Professional Look and Feel Using LINQ 182 at Your Fingertips 99 Adding a Tool Strip Container and Some Tools 99 Chapter 9 Adding a Status Bar to Your Browser 101 Personalizing Your Application with Windows Icons 104 Building Your Own Weather Tracker Application 187 Redoing the Browser 112 Exploring the Features of the Weather Tracker Application 188 Windows Presentation Foundation 112 Creating the Application User Interface 189 WPF and XAML 113 Adding Notification Area Capabilities 191 Chapter 7 Adding the Splash Screen and About Dialog Box 199 Fixing the Broken Blocks 125 Adding the Options Dialog Box 202 Using the MSN Weather Web Service 204 Debugging an Application 126 Connecting to MSN Weather Web Services 206 Using a DLL in an Application 126 Setting User and Application Preferences 210 Using Breakpoints, Locals, Edit and Continue, and Working in the Background 211 Visualizers 128 Completing the Core Weather Tracker Functionality 219 Chapter 8 Testing Weather Tracker 225 Working with the Options Dialog Box 226 Managing the Data 141 Testing Weather Tracker Options 229 What Is a Database? 142 And Now, Just ClickOnce 229 What’s in a Database? 142 What Are Data Normalization and Data Integrity? 143 What Is Null? 145 Glossary 235 What Are Primary Keys and Foreign Keys? 146 Index 237 How Do You Interact with a Relational Database? 148 iv Microsoft Visual Basic 2008 Express Edition: Build a Program Now! Introduction Microsoft Visual Basic 2008 Express Edition (and the work with matrices and plot graphics for my math class,” other Visual Studio 2008 Express Edition products) is, in my and many more projects that you can imagine! opinion, one of the best and most intelligent ideas to come This book is for people who have ideas but don’t know from the Developer Division at Microsoft. I’m applauding how to bring them to reality. And it’s a good introduction and cheering for the people who had this brilliant idea to the art and science of developing software. because I believe there is a real need and demand for a world-class, powerful product for hobbyist programmers, How This Book Is Organized students, and professional developers. And Visual Basic 2008 Express Edition provides all of that and more. This book consists of nine chapters, each covering a Visual Basic 2008 Express Edition is a fully functional particular feature or technology about Visual Basic 2008 subset of Visual Studio 2008, suitable for creating and Express Edition. Most chapters build on previous chapters, maintaining Windows applications and libraries. It’s not so you should plan on reading the material sequentially. a timed-bomb edition, a demo, or a feature-limited version—no, it’s a key Microsoft initiative to reach more Conventions and Features in This Book people and give them the ability to have fun while creating cool software. This book presents information using conventions designed to make the information readable and easy to Who Is This Book For? follow. Before you start the book, read the following list, which explains conventions you’ll see throughout the book This book is for everybody: students, hobbyist pro- and points out helpful features in the book that you might grammers, and people who always thought programming want to use: was a tough task. It’s for people who have ideas like “I wish ■ Each exercise is a series of tasks. Each task is presented I could build a tool to store all my recipes and then print them and send them to my friends,” “I wish I could build as a series of numbered steps (step 1, 2, and so on). this cool card game that I have never found elsewhere,” “I Each exercise is preceded by a procedural heading that wish I could build this cool software to store my DVD and lets you know what you will accomplish in the exercise. CD collection,” “I wish I could build this software to help me Introduction v ■ Boxes labeled TIP, NOTE, MORE INFO, and so on, pro- ■ 1 GHz 32-bit (x86) processor vide additional information or alternative methods for ■ 1 GB MB RAM (512 MB minimum) completing a step successfully.