The book of visual basic 2005 net insight for classic vb developers 2006 - phần 1 docx

51 218 0
The book of visual basic 2005 net insight for classic vb developers 2006 - phần 1 docx

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

From the author of the highly acclaimed Book of ™ VB .NET comes this comprehensive introduction to Visual Basic 2005, the newest version of Microsoft’s popular programming language. If you’re a developer who is new to the language, you will learn to use VB 2005 effectively. If you’re from the old school of VB but haven’t yet made the jump to .NET, you will be able to make the transition seamlessly. And you won’t have to wade through boring, unnecessary material before you get there. This guide covers all the necessities, ditching jargon and getting right to the substance of how to: • Implement object-oriented programming with classes, interfaces, and inheritance • Design well-behaved multithreaded applications • Work with XML, file streams, and ADO.NET, the .NET toolkit for relational databases • Build code-driven web pages and rich Windows applications • Deploy your applications with snazzy setup programs Conversational in tone and eminently readable, this book tackles VB 2005’s hot new features and explains how to work with .NET, but it doesn’t water the informa- tion down for beginners. After a brief overview of changes from VB 6, you’ll get real-world examples in each chapter that will get you up to speed and ready to perform in the VB 2005 environment. Helpful code examples, references to additional online material, and tips on planning, design, and architecture round out The Book of Visual Basic 2005. Professional developers who need to master VB 2005 will want this book by their side. About the author Matthew MacDonald is a developer, author, and educator dedicated to all things Visual Basic and .NET. He’s worked with Visual Basic and ASP since their initial versions, and he has written more than a dozen books, including The Book of VB .NET (No Starch Press) and Visual Basic 2005: A Developer’s Notebook (O’Reilly). YOUR PAS S PORT TO THE WORLD OF .NET YOUR PAS S PORT TO THE WORLD OF .NET www.nostarch.com “I lay flat.” This book uses RepKover —a durable binding that won’t snap shut. TH E FI N EST I N G E E K E N TE RT A I N M E NT ™ SHELVE IN: PROGRAMMING LANGUAGES/ VISUAL BASIC $39.95 ($51.95 CDN) M AC D O NA L D V I SUA L BA SIC 2005 V I SUA L BA SIC 2005 T H E B O O K of M a t t h e w M a c D o n a l d V ISUA L BA SIC 2005 V ISUA L BA SIC 2005 . N E T I N S I G H T F O R C L A S S I C V B D E V E L O P E R S bvb_02.book Page ii Thursday, March 30, 2006 12:39 PM THE BOOK OF ™ VISUAL BASIC 2005 .NET Insight for Classic VB Developers by Matthew MacDonald San Francisco bvb_02.book Page iii Thursday, March 30, 2006 12:39 PM THE BOOK OF VISUAL BASIC 2005. Copyright © 2006 by Matthew MacDonald. All rights reserved. No part of this work may be reproduced or transmitted in any form or by any means, electronic or mechanical, including photocopying, recording, or by any information storage or retrieval system, without the prior written permission of the copyright owner and the publisher. Printed on recycled paper in the United States of America 1 2 3 4 5 6 7 8 9 10 – 09 08 07 06 No Starch Press and the No Starch Press logo are registered trademarks of No Starch Press, Inc. Other product and company names mentioned herein may be the trademarks of their respective owners. Rather than use a trademark symbol with every occurrence of a trademarked name, we are using the names only in an editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the trademark. Publisher: William Pollock Managing Editor: Elizabeth Campbell Associate Production Editor: Christina Samuell Cover and Interior Design: Octopod Studios Developmental Editor: Jim Compton Technical Reviewer: Dan Mabbutt Copyeditor: Neil Ching Compositor: Riley Hoffman Proofreader: Stephanie Provines For information on book distributors or translations, please contact No Starch Press, Inc. directly: No Starch Press, Inc. 555 De Haro Street, Suite 250, San Francisco, CA 94107 phone: 415.863.9900; fax: 415.863.9950; info@nostarch.com; www.nostarch.com The information in this book is distributed on an “As Is” basis, without warranty. While every precaution has been taken in the preparation of this work, neither the author nor No Starch Press, Inc. shall have any liability to any person or entity with respect to any loss or damage caused or alleged to be caused directly or indirectly by the information contained in it. Library of Congress Cataloging-in-Publication Data MacDonald, Matthew. The Book of Visual Basic 2005 : .NET Insight for Classic VB Developers / Matthew MacDonald. p. cm. Includes index. ISBN 1-59327-074-7 1. Microsoft Visual BASIC. 2. BASIC (Computer program language) 3. Microsoft .NET Framework. I. Title. QA76.73.B3M282 2005 005.2'768 dc22 2005028823 bvb_02.book Page iv Thursday, March 30, 2006 12:39 PM For Faria bvb_02.book Page v Thursday, March 30, 2006 12:39 PM ACKNOWLEDGMENTS The collection of .NET titles on bookstore shelves is embarrassingly large. When writing a book about a language as popular as Visual Basic, the challenge isn’t finishing it, but making sure that it’s really insightful, friendly, and useful beyond the standard Microsoft documentation. To that end, I have to thank countless other developers and .NET aficionados whose words—in books, articles, websites, discussions groups, and emails—have provided the seeds of insight that have enhanced the pages of this book. I hope the readers of this book will also learn from and become a part of the broader .NET community. Closer to home, I should thank all the pleasant people at No Starch Press who have worked with me throughout this project, for both this edition and the previous one, including Bill Pollock, Karol Jurado, Christina Samuell, Elizabeth Campbell, and Amanda Staab. I also owe a heartfelt thanks to this book’s reviewers, Dan Mabbutt of About.com fame and Jim Compton, and its copyeditor, Neil Ching. Lastly, I need to thank my parents (all four of them) and my loving wife. bvb_02.book Page vi Thursday, March 30, 2006 12:39 PM BRIEF CONTENTS Introduction 1 Chapter 1: The .NET Revolution 7 Chapter 2: The Design Environment 19 Chapter 3: VB 2005 Basics 47 Chapter 4: Windows Forms 87 Chapter 5: Object-Oriented Programming 135 Chapter 6: Mastering Objects 173 Chapter 7: Assemblies and Components 211 Chapter 8: Bug Proofing 239 Chapter 9: Dealing with Data: Files, Printing, and XML 271 Chapter 10: Databases and ADO.NET 311 Chapter 11: Threading 355 Chapter 12: Web Forms and ASP.NET 387 Chapter 13: Web Services 425 Chapter 14: Setup and Deployment 451 Index 475 bvb_02.book Page vii Thursday, March 30, 2006 12:39 PM bvb_02.book Page viii Thursday, March 30, 2006 12:39 PM CONTENTS IN DETAIL INTRODUCTION 1 Who Should Read This Book 2 What You Will Learn 2 Code Samples 3 Complaints, Adulation, and Everything in Between 3 Chapter Overview 4 What Comes Next? 5 1 THE .NET REVOLUTION 7 A Brief History of Visual Basic 7 Enter .NET 8 The Limitations of “Classic” Visual Basic 8 Visual Basic’s Quirky Mix 8 Isolated Languages 9 Enterprise Development Headaches 9 DLL Hell 9 Incomplete Support for Object-Oriented Programming 10 The .NET Vision 10 The Ingredients of .NET 10 The Common Language Runtime (CLR) 11 The .NET Classes 11 Speaking the Same Language 12 Deep Language Integration 13 Prebuilt Infrastructure 13 Web Services and the Next-Generation Internet 14 Open Standards: XML, SOAP, WSDL, and Other Letters from the Alphabet 14 Metadata: The End of DLL Hell? 15 Is VB 2005 Still VB? 15 Ten Enhancements You Can’t Live Without 16 Ten Changes That May Frustrate You 16 The Dark Side of .NET 17 What About COM? 17 What Comes Next? 18 2 THE DESIGN ENVIRONMENT 19 New in .NET 20 Starting Out in the IDE 21 The Start Page 22 Changing the Startup Behavior 23 bvb_02.book Page ix Thursday, March 30, 2006 12:39 PM x Contents in Detail Creating a Project 24 Tabbed Documents 25 Docked and Grouped Windows 26 Touring Visual Studio 27 The Solution Explorer 27 The Toolbox 28 The Properties Window 30 The Code Display 31 Splitting Windows 32 The Task List 34 Code Snippets 35 Inserting a Snippet 35 Managing Snippets 36 Macros 37 The Macro IDE 38 The Temporary Macro 39 Macros with Intelligence 39 Macros and Events 40 The Simplest Possible .NET Program 41 MyFirstConsoleApplication Files 43 MyFirstConsoleApplication Directories 43 Project Properties 44 What Comes Next? 46 3 VB 2005 BASICS 47 New in .NET 48 Introducing the Class Library 49 Namespaces 49 Assemblies 51 Types 52 Using the Class Library 53 Adding a Reference to an Assembly 53 Importing a Namespace 55 Exploring the Class Library Namespaces 57 The My Object 60 Code Files 62 Class and Module Blocks 63 Namespace Blocks 64 Adding Code Files 64 Data Types 65 The System Types 65 Multiple Variable Declaration 66 Initializers 66 Data Types as Objects 67 Strings 67 More Efficient Strings 70 Dates and Times 71 Arrays 71 Arrays and IEnumerable 72 bvb_02.book Page x Thursday, March 30, 2006 12:39 PM [...]... 10 0 Handling More Than One Event 10 2 Accept and Cancel Buttons 10 3 Exploring NET Forms 10 4 Two Ways to Show a Form 10 4 Forms and the My Object 10 6 Modal Forms 10 7 The Startup Form and Shutdown Mode 10 8 Application Events 10 8 Form Oddities 11 0 The Inner Workings of Forms 11 1 Visual Basic 6 Forms... 6 Forms “Under the Hood” 11 2 Visual Basic 2005 Forms “Under the Hood” 11 3 Stepping Through the “Muck and Goo” 11 5 What About Binary Information? 11 6 C on t en ts in D et ail xi bvb_02 .book Page xii Thursday, March 30, 2006 12 :39 PM Adding Controls Dynamically 11 7 Dynamic Event Hookup 11 8 Interaction Between Forms 12 0 A Sample Form Interaction... the Visual Basic makeover many programmers have spent years waiting for This book provides a guided tour through the world of Visual Basic 2005 In it, you’ll learn how you can use your existing VB skills and master the NET way of thinking Who Should Read This Book This book is aimed at Visual Basic 6 developers who want to shed some of their current habits and start learning about how the NET platform... and hacks either failed or risked serious side effects And there was no way to drop projects from earlier versions of Visual Basic into the new VB NET world So how does Visual Basic 2005 fit into this evolution? Visual Basic 2005 is VB NET 2.0 Microsoft marketers decided that the NET moniker was confusing the heck out of pretty much everyone, so they dropped it However, they didn’t change the language... people find Microsoft’s new platform so exciting I n tr od uct io n 5 bvb_02 .book Page 6 Thursday, March 30, 2006 12 :39 PM bvb_02 .book Page 7 Thursday, March 30, 2006 12 :39 PM 1 THE NET REVOLUTION This chapter presents the “big picture” of Visual Basic and the NET Framework You’ll get an overview of what has changed, why it’s different, and just what life will be like in the NET world Along the way, we’ll... 2 Thursday, March 30, 2006 12 :39 PM Now Microsoft has introduced Visual Basic 2005, along with the second version of the NET Framework Microsoft’s developers have expended considerable resources making Visual Basic 2005 easier to understand, use, and embrace, and they’re earmarking this release as the version that will finally make die-hard classic VB- ers switch to NET So have they succeeded? As you’ll... step up from classic VB, and it’s claiming it works a lot more like classic VB does In a few superficial cases, this is true (as with the return of edit-and-continue) But overall, it’s no easier to move to Visual Basic 2005 than it was to move to VB NET 1. 0 The Limitations of Classic Visual Basic Have you heard the argument, “Before you can understand the solution, you have to understand the problem”?... which gave us the easiest way to go “object-oriented.” Enter NET When Visual Basic NET hit the scene, life changed dramatically That’s because VB NET 1. 0 was the first version of Visual Basic that broke language compatibility And it didn’t do it meekly Suddenly, commands that VB programmers had been able to use since Visual Basic 1. 0 earned a blank stare from the VB NET compiler Traditional VB programming... classes The NET Framework sits on top of the Windows platform, which provides its own set of services (for example, the IIS server built into Windows lets your computer be a web server) Figure 1- 1 shows the relationship The NET Framework Unified Classes Common Language Runtime Windows Operating System Services (COM+, Transactions, Message Queuing, etc.) Figure 1- 1 : The NET Framework 10 C ha pt er 1 bvb_02 .book. .. point, the people at Microsoft decided to start over and build a new set of languages from the ground up The NET Framework is the result of that effort The Ingredients of NET Like COM and ActiveX, the NET Framework means a lot of different things, depending on whom you talk to in Microsoft’s marketing department On the programming side, NET is made up of the Common Language Runtime (CLR) and a set of unified . Mode 10 8 Application Events 10 8 Form Oddities 11 0 The Inner Workings of Forms 11 1 Visual Basic 6 Forms “Under the Hood” 11 2 Visual Basic 2005 Forms “Under the Hood” 11 3 Stepping Through the “Muck. indirectly by the information contained in it. Library of Congress Cataloging-in-Publication Data MacDonald, Matthew. The Book of Visual Basic 2005 : .NET Insight for Classic VB Developers / Matthew. 9 Incomplete Support for Object-Oriented Programming 10 The .NET Vision 10 The Ingredients of .NET 10 The Common Language Runtime (CLR) 11 The .NET Classes 11 Speaking the Same Language 12 Deep Language

Ngày đăng: 13/08/2014, 08:21

Tài liệu cùng người dùng

Tài liệu liên quan