1. Trang chủ
  2. » Khoa Học Tự Nhiên

Programming microsoft visual basic

1,3K 124 0

Đ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

Thông tin cơ bản

Định dạng
Số trang 1.304
Dung lượng 7,03 MB

Nội dung

This document is created with a trial version of CHM2PDF Pilot http://www.colorpilot.com Programming Microsoft Visual Basic 2005: The Language byFrancesco Balena Microsoft Press 2006 (1024 pages) ISBN:0735621837 Use this comprehensive guide to get the essential, straightforward information you need to master the core capabilities of Visual Basic 2005 Table of Contents Programming Microsoft Visual Basic 2005—The Language Introduction Part I - The Basics Chapter - Introducing the Microsoft NET Framework Chapter - Basic Language Concepts Chapter - Control Flow and Error Handling Chapter - Using Visual Studio 2005 Chapter - Debugging Visual Basic Applications Part II - Object-Oriented Programming Chapter - Class Fundamentals Chapter - Delegates and Events Chapter - Inheritance Chapter - Object Lifetime Chapter 10 - Interfaces Chapter 11 - Generics Part III - Working with the NET Framework Chapter 12 - NET Basic Types Chapter 13 - Arrays and Collections Chapter 14 - Regular Expressions Chapter 15 - Files, Directories, and Streams Chapter 16 - The My Namespace Chapter 17 - Assemblies and Resources Part IV - Advanced Topics Chapter 18 - Reflection Chapter 19 - Custom Attributes Chapter 20 - Threads Chapter 21 - Serialization Chapter 22 - PInvoke and COM Interop Index List of Figures List of Tables This document is created with a trial version of CHM2PDF Pilot http://www.colorpilot.com Back Cover Get the essential, straightforward information you need to master the core capabilities of Visual Basic 2005 Focusing on the language and the Microsoft NET Framework 2.0 base class library, a well-known authority on Visual Basic provides both new and experienced developers the pragmatic guidance and examples they need to build innovative solutions Discover how to: Compress files, manipulate ACLs, use semaphores, and exploit other new capabilities in the NET Framework 2.0 Implement generics to define a type-safe data structure Use inheritance, polymorphism, interfaces, delegates, and attributes to write flexible applications Use the My namespace to perform common tasks more easily Work with the new editing and debugging features of Microsoft Visual Studio 2005 Master regular expressions and perform complex text searches and input validation Take advantage of streams, serialization, and threading techniques Implement advanced programming techniques based on custom attributes, reflection, and onthe-fly Interact with legacy code by using Pinvoke and COM Interop Understand key differences from Visual Basic 6.0 About the Author Francesco Balena has been programming with Visual Basic since version 1.0 He is the author of many Microsoft Press titles, including the widely acclaimed prior editions of this book Francesco is a cofounder of Code Architects srl, an Italian software company that specializes in using Microsoft technologies to create enterprise-level solutions and programming tools In addition, he is a regional director for MSDN Italy, and a popular speaker at developer conferences This document is created with a trial version of CHM2PDF Pilot http://www.colorpilot.com Programming Microsoft Visual Basic 2005—The Language Francesco Balena (Code Architects) Published By Microsoft Press A Division of Microsoft Corporation One Microsoft Way Redmond, Washington 98052-6399 Copyright © 2006 by Francesco Balena ISBN:0735621837 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 2005936844 Printed and bound in the United States of America QWT 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/learning/ Send comments to mspinput@microsoft.com Microsoft, Active Directory, ActiveX, Authenticode, Excel, IntelliSense, JScript, Microsoft Press, MSDN, Visual Basic, Visual C#, Visual C++, Visual Studio, the Visual Studio logo, Win32, Windows, Windows NT, and Windows Server are either registered trademarks or trademarks of Microsoft Corporation in the United States and/or other countries 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 Project Editor: Kathleen Atkins Technical Reviewer: Jack Beaudry Copy Editor: Christina Palaia Indexer: Lynn Armstrong Body Part No X11-53584 Acknowledgments First of all, I am glad to have the opportunity to thank my friend Giuseppe Dimauro, for helping me better understand the many secrets behind the Microsoft Windows and NET Framework platforms Even more important, in these six months Giuseppe had to run Code Architects, the software and consulting company that we founded a few years ago, virtually by himself I am happy I can finally go back to the fight! Enrico Sabbadin is a true expert in n-tier enterprise applications, COM+, and security, and I feel very lucky he could review all the chapters while I was writing them He provided many valuable suggestions I'd like to thank Marco Bellinaso and Alberto Falossi, two pillars of the Code Architects team While I was busy on this book, Marco did a marvelous job with our U.S Web site (http://www.dotnet2themax.com) and Alberto did the same with our Italian Web site (http://www.dotnet2themax.it) Next come all the wonderful people at Microsoft Press Kathleen Atkins has taken care of all my books, and she is so marvelous that I can't even think of writing a book with another editor Jack Beaudry helped in finding typos and mistakes in code, whereas Christina Palaia did the same with my prose English isn't my mother tongue, so you can imagine what kind of job she had to face This book would be very different—or might have never been printed at all—if it weren't for Ben Ryan, my acquisitions editor, who accepted my proposal and offered many suggestions on how to improve the original structure Finally, my family Living with a full-time coder and writer isn't easy Only a special woman like my wife, Adriana, can it in such a delightful way And only a special boy like my son, Andrea, has permission to break into my room to talk about his favorite movie or to ask for help with his homework I can't thank both of you enough for always reminding me that the most important things in life can't be rendered as a sequence of bytes, regardless of the programming language you're using This document is created with a trial version of CHM2PDF Pilot http://www.colorpilot.com Francesco Balena Francesco Balena began his software studies in the late 1970s and had to fight for a while with huge IBM mainframes and tons of punched cards while he waited for the PC to be invented From those good old days—when the word megabyte made little sense and gigabyte was pure blasphemy—he retained his taste for writing the most efficient and resource-aware code possible In more recent years, Francesco has become a contributing editor and member of the Technical Advisory Board of Visual Studio Magazine (formerly Visual Basic Programmer's Journal), for which he has written more than 80 articles and columns He's the author of the best-sellers Programming Microsoft Visual Basic 6.0, Programming Microsoft Visual Basic NET, and Programming Microsoft Visual Basic NET Version 2003, as well as coauthor of Applied NET Framework Programming in Microsoft Visual Basic NET (with Jeffrey Richter) and Practical Guidelines and Best Practices for Microsoft Visual Basic and Visual C# Developers (with Giuseppe Dimauro), all from Microsoft Press Francesco teaches Microsoft Visual Basic and C# courses in the United States and Europe and speaks at developer conferences such as VSLive!, SQL2TheMax, WinDev, and WinSummit He is the founder of the popular NET-2-The-Max site (http://www.dotnet2themax.com), where you can find articles, tips, routines, and updates as they occur for this book Francesco is the lead author of VBMaximizer, a best-seller add-in for Microsoft Visual Basic that has won an award from readers of Visual Studio Magazine, and he is coauthor of CodeBox for NET (a code repository tool) and Form Maximizer for NET (a set of Microsoft Windows Forms controls) Since 2002, he has been the Microsoft MSDN Regional Director for Italy and is cofounder of Code Architects, an Italian company that specializes exclusively in Microsoft NET Framework programming and training and that consults for many large software companies in Italy, including Microsoft Francesco lives in Bari, Italy, with his wife, Adriana and his son, Andrea, but spends a lot of his time abroad In a previous life, he had many good times playing his alto sax with big bands and jazz combos until he found that computer programming can be just as much fun and doesn't require that he be awake and blowing until A.M each and every night Only later did he realize that—to write code and meet deadlines—he wouldn't be going to sleep before A.M anyway, but it was too late to change his mind This document is created with a trial version of CHM2PDF Pilot http://www.colorpilot.com Introduction Finding a reference book on Microsoft Visual Basic 2005 is easy By the time this book reaches the bookstores, you'll find plenty of Visual Basic books on the shelves Why should you buy this one? What makes this book different? When I began to write this book, I asked myself similar questions How can a book compete with Microsoft Visual Studio manuals and all the samples and tips you can find on the Internet? To answer this question I need to take a short historical detour Where Visual Basic is Coming From and Heading To I have been teaching Visual Basic since the early 1990s, well before it became Visual Basic NET, and I taught (and wrote about) Microsoft QuickBasic before then I have seen this language evolve from the time that you were practically compelled to use GoTo statements to make things work up to today's phenomenal object-oriented features Everything has changed in these 20 years, except one thing: developers have always underutilized—or even misused—this language For instance, Microsoft Visual Basic was the first version to offer the ability to define classes, yet very few developers actually used classes in their applications The few who did, however, were able to catch the Microsoft NET Framework wave easier than their colleagues were and could deliver more powerful Visual Basic NET applications in less time Another example: Microsoft Visual Basic developers were able to access a database through ActiveX Data Objects (ADO) using client-side recordsets in disconnected mode, but many preferred to ignore this feature and continued to work with easier-to-use but less scalable serverside cursors (And they had serious problems when writing large client/server applications.) Versions 2002 and 2003 of Visual Basic NET are very powerful development platforms, yet I see that many developers are missing their full potential For example, features such as threading, reflection, and custom attributes can really revolutionize the way you write applications, but only a minority of programmers leverage them The gap between what the language offers and what most developers actually use has always been large, but it is going to become larger with Visual Basic 2005, which offers great new features such as generics, custom events, operator overloading, and many other object-oriented enhancements This document is created with a trial version of CHM2PDF Pilot http://www.colorpilot.com Becoming a Better Developer The bottom line is: developers don't need yet another reference manual Instead—better, in addition to a reference—they need to understand how the old and the new features can be used to create more efficient, robust, reusable, and secure code In the programming world, you can often achieve the same result with two or more equivalent techniques, but each one has its specific pros and cons, and often selecting the right approach can have far-reaching consequences on the end result You need more than a mere reference book to gain the knowledge needed to detect these subtle differences A common misunderstanding in the programming community is that all you need to write great applications is familiarity with the NET Framework and related technologies, such as Windows Forms and ASP.NET Granted, you need to learn these technologies to create real-world programs, but that familiarity isn't a surrogate for in-depth knowledge of low-level mechanisms that enable you to reduce memory and resource consumption, adopt effective optimization techniques, or leverage inheritance to write more concise and reusable code I have seen too many applications that have a great user interface, yet perform very slowly and aren't structured in an orderly manner Maintaining and evolving these applications are nightmares and cost much more in time and money than if they had been written with a solid understanding of the NET Framework basics in mind Another facet of programming that many developers tend to overlook is the quest for thorough knowledge of the tool you spend most of your time with: Visual Studio I find it quite ironic that most developers can argue for hours about which language can be more efficient or productive, yet they fail to leverage Visual Studio to its full potential, for example, by learning how to write macros, templates, and code snippets, or how to customize the IDE to fit their needs or programming style This document is created with a trial version of CHM2PDF Pilot http://www.colorpilot.com Not the Usual Programming Language Reference For all these reasons, I decided that I wanted to write something different from the typical language reference, something that would cover all the language features and show real-world cases when these features can be used profitably The problem with this approach is that it tends to take a lot of space Clearly, a book on this premise would be remarkably thicker than a standard reference book, and it would take me much longer to write If this book would cover the entire Visual Basic potential—including both the language features and higher-level technologies such as Windows Forms and ASP.NET—it would have exceeded the number of pages that Microsoft Press can bind in a book And it would have hit the streets too many months after the Visual Basic 2005 release In the end, I saw that the only realistic solution to this issue was focusing on the language and most of the NET Framework foundation classes—memory management, serialization, threading, reflection, PInvoke, and COM Interop—and leaving out mportant topics such as Windows Forms, ASP.NET Web Forms and Web Services, and ADO.NET It was a painful decision, but now that the book is completed, I am very glad I took this route This is a book I have had in mind for years, and I finally had the opportunity to write it Note As of this writing, I am planning to write at least one other book in the Programming Microsoft Visual Basic 2005 series, but I haven't finalized the agreement with the publisher, and thus I can't be more precise about the topics I'll cover in a forthcoming book(s) If you want to learn more, read my Weblog or subscribe to my Web site's newsletter (Information on how to this is provided later in this introduction.) This document is created with a trial version of CHM2PDF Pilot http://www.colorpilot.com Live Updates and Feedback Even though I have been working with Visual Basic, C#, and the NET Framework for so many years, I continue to learn something new almost every day You can learn more about my discoveries by visiting my Web site, where I maintain the home page for this and all my other books, at this URL: http://www.dotnet2themax.com You can also subscribe to the site's newsletter and receive information about new articles and code snippets available online Or you can read my English Weblog (see Figure I-1) where I post updates about this book, comments from readers, plans for future Microsoft Press books, and so forth: http://www.dotnet2themax.com/blogs/fbalena Figure I-1: My Weblog Tip Select the Books category to read all posts related to this and other forthcoming books Writing this book has been a challenge I think (and hope) I did a good job, but I surely look forward to hearing your comments, reactions, and suggestions for improvements You can leave a comment at my Weblog or write me at fbalena@dotnet2themax.com or fbalena@codearchitects.com This document is created with a trial version of CHM2PDF Pilot http://www.colorpilot.com Who Is This Book For? The short answer is that this book is for all Visual Basic 2005 developers A more articulated answer is that this book is addressed to the following people: Developers who have been writing applications with versions 2002 and 2003 of Visual Basic NET and want to learn all the new features in Visual Basic 2005 as quickly as possible Visual Basic programmers who are facing the daunting task of converting their skills and their applications to Visual Basic 2005 and the NET Framework Programmers who are already familiar with another programming language—for example, C, C#, C++, Java, or Borland Delphi—and who want to learn quickly how to write Visual Basic 2005 applications Expert Visual Basic developers who want to learn more about advanced NET Framework programming techniques, such as memory optimization, object serialization, and threading Programmers of any expertise level who want to write robust and maintainable applications by leveraging objectoriented features of Visual Basic and other NET Framework techniques, such as reflection and custom attributes Of course, not all the chapters in this book will require the same degree of attention from each of the preceding groups For example, Visual Basic novices will spend most of their time digesting the first half of the book, whereas expert programmers will find the second half more intriguing Developers coming from edition 2003 of Visual Basic NET will probably focus on chapters that are interspersed here and there in the book, for example, Chapter ("Using Visual Studio 2005"), Chapter ("Debugging Visual Basic Applications"), Chapter 11 ("Generics"), and Chapter 16 ("The My Namespace") VB6 to Visual Studio 2005 Visual Basic developers switching to Visual Studio 2005 should carefully read the sections marked with this icon In these sections, I focus on the important differences between these two languages as well as subtle issues you might face when migrating a Visual Basic application to the NET Framework Version 2005 of VB or Version 2.0 of NET Sections marked with this icon describe features that have been added in version 2005 of the Visual Basic language or in version 2.0 of the NET Framework Notice that some features are so important that I devote an entire chapter to them, in which case this icon appears only at the top of the chapter Otherwise, some really minor improvements are mentioned in text without being described in a section of their own This document is created with a trial version of CHM2PDF Pilot http://www.colorpilot.com Organization of This Book Programming Microsoft Visual Basic 2005: The Language is broadly organized in four parts The first three chapters of Part I cover the language basics If you aren't new to Visual Basic, you might skip them, even though you might find some interesting tips here and there If you are switching from Visual Basic or Visual Basic NET 2003, you can simply stop at the Visual Basic and New icons, as described in the previous section Regardless of your familiarity with Visual Basic, however, I recommend that you read Chapters and carefully because they explain the many new features of the Visual Studio IDE and illustrate concepts that are used in subsequent chapters Part II is devoted to object-oriented features of the Visual Basic language Again, if you are already familiar with Visual Basic NET, you might want to spend more time on the sections marked with the New icon, but I suggest you read Chapter 7, "Delegates and Events," and Chapter 9, "Object Lifetime," because they illustrate advanced techniques that can improve your skills remarkably Chapter 11 is a must-read for learning more about the most intriguing and important new features of version 2.0 of the NET Framework Part III is about basic types in the NET Framework Chapter 16, "The My Namespace," contains an in-depth description of this new Visual Basic feature, but you'll surely find a lot of useful information in all the chapters in this part For example, Chapter 13, "Arrays and Collections," shows you how to work wonders with NET Framework complex data structures (including generics collection) My favorite chapter is Chapter 14, "Regular Expressions," where I describe all I've learned about this exciting (and very useful) NET Framework feature Part IV covers advanced programming topics, such as threading, serialization, PInvoke, and COM Interop These features can make your applications more powerful, but failing to use them properly can introduce many hard-to-find bugs; thus, read these chapters carefully Chapter 18, "Reflection," and Chapter 19, "Custom Attributes," are actually one very long chapter split into two: in the former, I offer a very complete reference on reflection, whereas in the latter I offer a few real-world (and quite complex) examples of the wonders custom attributes can for you This document is created with a trial version of CHM2PDF Pilot http://www.colorpilot.com Index V validation constructors and, 32–33 regular expressions and, 569–572 Value property, 544 value types See also ByVal arguments reference types vs., 4, 26–29, 31, 441–443 See also reference types structures as, 30 Values property, 513 ValueType type, 62, 441–443 variables, 42–83 accessing static members with instance, 24–25 arrays, 79–83 See also arrays block-scoped, 50–51 See also scope boxing and unboxing operations and, 28–29 Char type vs String type, 362 conversions See conversions data types See data types debugging windows and, 186–188 declarations and assignments, 42–52 See also assignments; declarations displaying values with data tips See data tips For…Next loop, 87, 88 global See global variables initializers, 48–49 See also initializers local See local variables local, class, and static, in threads, 832–833 For loops and, 52 multiple variable declarations, 47–48 naming convention, 19 object assignments, 49–50 operators See operators Option Explicit and Option Compare directives, 44–45 Option Strict directive, 45–47 Refactor! tool commands, 159–160 reference types vs value types and, 26–29 root, 343 unassigned and unused, 43–44 variable enregistration, 242 Variant type, 52, 104 VB Default page, Options dialog box, 45–46 See also Options dialog box vb files, 15 VBC_VER compilation constant, 139 vbmacros files, 178 vbNullString constant, 100 vectors, 489 version-tolerant serialization (VTS), 886–888 Binder property, 887–888 OptionalField attribute, 887 overview, 886–887 versioning See also version-tolerant serialization (VTS) assemblies and, 3–4, 677 NET Framework and, 8–9 setting runtime version in configuration files, 706–708 strong-named assemblies, 685 version policy in application configuration files, 698–701 Visual Basic version, 139 views See windows, Visual Studio 2005 virtual classes, 323–325 virtual methods constructors, 314–315 creating, 311–313 interface, 375 MyClass keyword and, 318 overridable methods as, 22, 311 scope and, 327 Visual Studio 2005 and, 311 visibility See scope This document is created with a trial version of CHM2PDF Pilot http://www.colorpilot.com Visual Basic 2005 application framework, 626–627 arrays See arrays assemblies and resources See assemblies; resources attributes, 39–42 See also attributes classes, 19–32 See also classes collections See collections Common Type Specifications (CTS) and, custom attributes See custom attributes debugging applications See debugging delegate covariance and contravariance in, 763–764 delegates, 281–290 See also delegates error handling See error handling events, 290–306 See also events execution flow control See execution flow control files, directories, and streams See directories; files; streams generics See generics inheritance See inheritance installed code snippets, 158 interfaces See interfaces mapping data types of, to NET Framework data types, 61–62 See also data types Microsoft NET Framework and See NET Framework modules, 15–19 See also modules My namespace See My namespace namespaces, 32–39 See also namespaces NET programming languages and, object lifetime See object lifetime reflection See reflection Reflector decompiler cross-language conversion with C#, regular expressions See regular expressions serialization See serialization source code See code threads See threads unmanaged code and See COM Interop; PInvoke (Platform Invoke) variables See variables version constant, 139 Visual Basic and See Visual Basic Visual Studio 2005 and See Visual Studio 2005 Visual Basic arguments, 94 commands, functions, and constants, 100–104 Conversion class functions, 104 date and time functions, 102–103 error handling, 106, 119 fields as arguments, 241 file extensions, 15 FileSystem class commands and functions, 103–104 fixed-length strings, 58 Information class functions, 104 interaction commands and functions, 103 math functions, 101–102 Me keyword, 247 string comparisons, 383 string constants and functions, 100–101 unmanaged code and, Upgrade Visual Basic Code command, 53 Visual Basic 2005 vs., 85 See also Visual Basic 2005 Visual C# 2.0, See also C# programming language visual inheritance, 333–340 adding properties, methods, and events to base forms, 337–340 base form example, 334–335 inherited form example, 335–336 overview, 333–334 Visual Studio 2005 accessing online contents, 167 assemblies and, See also assemblies assembly attributes, 130 bookmarks, 152–153 build events, 130–132 Class Designer tool, 278–280 Class View window, 277–278 code, 143–160 See also code Code Editor, 143–146, 676 code snippets, 154–158 command-line arguments and, 18 Command window, 176–177 compiler-related attributes, 140–143 Configuration Manager, 136–140 customization features, 167–171 debugging features See debugging This document is created with a trial version of CHM2PDF Pilot http://www.colorpilot.com Dotfuscator Community Edition utility, Error List and Task List windows, 153–154 external tools and, 169–171 form inheritance and, 340 forms, 15 IDisposable interface and, 352 ILDASM (IL Disassembler) utility, 5–6 importing and exporting settings, 162 importing COM components, 929–930 macros and commands, 171–180 See also macros managing types with, 277–280 multiple-project solutions, 134–136 My Project designer, 130–134 See also My Project designer Object Test Bench window, 280 Options dialog box, 167–168 See also Options dialog box overridable methods and, 311–312 partial classes and, 23–24, 266–267 personalized toolbars and menus, 169 project and file templates, 126–127 See also templates project and item templates, 164–167 projects and solutions, 125–143 See also projects; solutions Properties window See Properties window refactoring code, 158–160 references to NET assemblies, 32–34 references to other assemblies, 132 Regular Expression Editor dialog box, 566 search and replace features, 148–152 Solution Explorer window, 127–129 static code analysis, 133–134 Team Edition for Software Developers See Team Edition for Software Developers tool windows, 161–162 Toolbox window, 676–677 Web Services applications and, 12 XML comments, 147–148 VisualizerObjectSource type, 193 visualizers, 190–194 custom, 190–194 predefined, 190 VolatileRead and VolatileWrite methods, 843–844 VSCodeGenAccessors.vb file, 221 vshost.exe.config files, 232 vsmproj files, 178 vssettings files, 162 vstemplate files, 164, 167 VTS See version-tolerant serialization (VTS) This document is created with a trial version of CHM2PDF Pilot http://www.colorpilot.com Index W WaitForChanged method, 596–597 WaitForPendingFinalizers method, 345 warnings, Error List window, 153 Watch window, 187 weak object references, 363–364 WeakReference object, 363–364 Web Forms applications ASP.NET and, 11–12 NET Framework and, 12 precompiling and, Windows Forms applications vs., 11 Web Services applications ASP.NET and, 11–12 My.WebServices object See My.WebServices object NET Framework and, 12 precompiling and, serviced components vs., 12 Web Services Enhancements (WSE) library, 12 Web Site command, 126 Web sites See also downloads Anakrino decompiler utility, Demeanor utility, Developer Express, 160 exception help, 105, 108 obfuscator utilities, Reflector decompiler utility, regular expressions, 566 Visual Studio 2005 and, 167 Web Services Enhancements (WSE) library, 12 WeekdayName method, 103 WeMethodAttribute attribute, 40 When keyword, 113–117 While clause, Do…Loop loop, 89 While…End While loops, 50–51, 90–91 widening conversions, 113 See also conversions Wildcards option, 149 Win32 processes, 10 Windows API, 13 Windows Explorer code editor tab context menu and, 144 as external tool, 171 shared assemblies and, 678 Solution Explorer window and, 127 Windows Forms applications ClickOnce applications, 11 Main method, 17 My.Application object See My.Application object My.Forms object See My.Forms object NET Framework and, 11 partial classes and, 266–267 plug-in framework example See plug-in framework example for Windows Forms applications precompiling and, threads in, 867–875 Windows Task Manager utility, 825–826 windows, Visual Studio 2005 Class Designer, 278–280 Class View, 277–278 data tip, 188–189 debugging, 186–188 macros for saving and loading, 179 Object Test Bench, 280 Performance Explorer, 224–225 splittable, 144 tool, 161–162 With…End With statements, 373 This document is created with a trial version of CHM2PDF Pilot http://www.colorpilot.com WithEvents keyword, 292–295 wizards, custom, 167 Write method, 22–23, 197 write-only properties, 248–251 WriteEntry and WriteException methods, 207 WriteIf method, 198, 201 WriteLine method, 22–23, 183, 197 WriteLineIf method, 198, 201 WriteOnly keyword, 248–249, 370 writing binary files, 611–613 files, 589–590 streams, 608 text files, 608–611 threads and volatile operations, 843–844 This document is created with a trial version of CHM2PDF Pilot http://www.colorpilot.com Index X XCOPY deployment NET Framework and, XCOPY as external tool, 171 XML ADO.NET and, 11 code snippet files, 155 configuration files and, 9, 699 searching for nested tags with regular expressions and, 572–573 serialization, 261, 878 XML comments, 147–148, 279 XML Editor, 155, 156–158 XML Visualizer, 190 XmlTextReader and XmlTextWriter types, 608 XmlWriterTextListener class, 202 XmlSerializer type, 782–783 Xor method, 520 Xor operator, 71–72 This document is created with a trial version of CHM2PDF Pilot http://www.colorpilot.com Index Y year template parameter, 166 This document is created with a trial version of CHM2PDF Pilot http://www.colorpilot.com Index Z zero-based arrays, 79 zero-element arrays, 82–83 ZeroFree* methods, 926 This document is created with a trial version of CHM2PDF Pilot http://www.colorpilot.com List of Figures Introduction Figure I-1: My Weblog Chapter 1: Introducing the Microsoft NET Framework Figure 1-1: The layers in the NET Framework Figure 1-2: The ILDASM tool Figure 1-3: The PreEmptive Solutions's Dotfuscator Community Edition tool Figure 1-4: The Windows\Assembly directory of a computer on which both versions 1.1 and 2.0 of the NET Framework have been installed Figure 1-5: A Win32 process can host multiple AppDomains AppDomains running in the same process can communicate more efficiently than AppDomains in different processes Chapter 2: Basic Language Concepts Figure 2-1: The Application page, which you display by double-clicking My Project in the Solution Explorer window Options in the lower half of the page become active only in Windows Forms projects Figure 2-2: Source files containing automatically generated code, which appear in the Solution Explorer only if you select the Show All Files option on the toolbar Figure 2-3: The Compile page of the My Project designer Figure 2-4: Disassembling a module using ILDASM Figure 2-5: The Add Reference dialog box Figure 2-6: The References folder in the Solution Explorer window Figure 2-7: The References page of the My Project designer (left) and the Unused References dialog box (right) Figure 2-8: Setting class-level attributes in the Properties window Figure 2-9: The VB Defaults page of the Options dialog box Figure 2-10: The Upgrade Visual Basic tool Chapter 3: Control Flow and Error Handling Figure 3-1: The dialog box that appears when an unhandled exception is thrown and one or more NET debuggers are installed on the computer Figure 3-2: The hierarchy of the most important exception objects in the NET Framework Figure 3-3: The Advanced Compiler Settings dialog box, which you display by clicking the Advanced Compile Options button on the Compile page of the My Project designer Chapter 4: Using Visual Studio 2005 Figure 4-1: The New Project dialog box (Test projects are available if you have installed the Visual Studio 2005 Team Edition for Software Developers.) Figure 4-2: The New Web Site dialog box Figure 4-3: Searching online for code snippets and additional starter kits Figure 4-4: Copying a data file to the output directory (This option isn't available in ASP.NET projects.) Figure 4-5: The Open With dialog box Figure 4-6: The Add As Link option of the Add Existing Item dialog box (This option isn't available for ASP.NET projects.) Figure 4-7: The Assembly Information dialog box Figure 4-8: The Build Events dialog box (left) and the Post-Build Event Command Line dialog box (right) Figure 4-9: The References page of the My Project designer Figure 4-10: The Code Analysis page of the My Project designer Figure 4-11: The results of a code analysis session appearing in the Error List window This document is created with a trial version of CHM2PDF Pilot http://www.colorpilot.com Figure 4-12: Setting project and solution behavior in the Options dialog box Figure 4-13: The two tabs of the Project Dependencies dialog box Figure 4-14: Selecting the startup project (or projects) for the current solution Figure 4-15: The Configuration Manager main window (left) and the dialog box that lets you define a new solution and project configuration (right) Figure 4-16: The Advanced Compiler Settings dialog box Figure 4-17: Selecting the active solution configuration from the Visual Studio main toolbar Figure 4-18: The change tracking and filtered IntelliSense features Figure 4-19: The context menu of the editor tab Figure 4-20: The IDE Navigator window Figure 4-21: The code editor with line numbers enabled (note that line numbers account for collapsed regions of code) Figure 4-22: XML comments compiled in an XML file that is used by the Object Browser to better describe code elements Figure 4-23: The Find Symbol Results tool window Figure 4-24: The Find dialog box with its pop-up menu to help the developer with regular expression syntax Figure 4-25: The Bookmarks window Figure 4-26: The Error List window Figure 4-27: The Task List window, showing user comments (top) or user-defined tasks (bottom) Figure 4-28: Inserting a code snippet Figure 4-29: The Code Snippet Manager dialog box Figure 4-30: The Rename smart tag Figure 4-31: The Refactor! Extract Method command Figure 4-32: The Refactor! Flatten Conditional command Figure 4-33: Docking a tool window Figure 4-34: Two steps of the Import And Export Settings Wizard, which let you select the file to import (top) and the individual settings that should be imported or exported (bottom) Figure 4-35: The last step of the Export Template Wizard Figure 4-36: A custom project template in the New Project dialog box Figure 4-37: Filtering commands by typing the first characters of the command name on the Keyboard page of the Options dialog box Figure 4-38: The Commands tab of the Customize dialog box Figure 4-39: Adding ILDASM as an external tool Figure 4-40: The Macro Explorer Figure 4-41: The Microsoft Visual Studio Macro IDE Figure 4-42: The Command window Figure 4-43: Properties of a macro project Chapter 5: Debugging Visual Basic Applications Figure 5-1: All the commands that are available for a breakpoint Figure 5-2: The dialog box that lets you define a tracepoint Figure 5-3: The Breakpoints dockable window Figure 5-4: The Locals, Autos, Call Stack, and Watch tool windows Figure 5-5: A data tip window Figure 5-6: The XML Visualizer dialog box Figure 5-7: The custom file visualizer displays a file's properties and contents and even enables you to browse other files Figure 5-8: The custom image visualizer, which lets you copy and paste the image, select a different image from disk, and return a different bitmap object to the project being debugged Figure 5-9: The Exceptions dialog box Figure 5-10: The Exception Assistant dialog box This document is created with a trial version of CHM2PDF Pilot http://www.colorpilot.com Figure 5-11: The Performance tool Figure 5-12: The effect of a Trace.Fail method Figure 5-13: The DebugView utility from http://www.sysinternals.com Figure 5-14: The Add New Test dialog box Figure 5-15: The Create Unit Tests dialog box Figure 5-16: The Test Manager window Figure 5-17: The Test Results tool window Figure 5-18: The Test View tool window Figure 5-19: Displaying properties of a test method in the Properties window and the Test Manager window Figure 5-20: The dialog box where you can enable code coverage Figure 5-21: The Code Coverage Results tool window Figure 5-22: Color highlighting of code coverage Figure 5-23: The Performance Explorer window (left) and the Properties window that enables you to change all the settings for a given performance session (right) Figure 5-24: Two tabs of a summary produced at the end of a performance session Figure 5-25: The Security page of the My Project designer (left) and the Advanced Security Settings dialog box (right) Figure 5-26: IntelliSense grays out type members that can't be invoked when the application runs in the selected zone Chapter 6: Class Fundamentals Figure 6-1: The Class View window Figure 6-2: The Class Designer window Figure 6-3: The Create Instance dialog box Figure 6-4: The Object Test Workbench window Chapter 7: Delegates and Events Figure 7-1: The Event tab in the Properties window, which displays all the events that the currently selected control exposes Figure 7-2: WithEvents variable implementation, as seen from inside ILDASM Figure 7-3: The demo application showing how to display a Help message in a status bar when the mouse moves over a control Figure 7-4: The hidden delegate class generated by the Visual Basic compiler Chapter 8: Inheritance Figure 8-1: The list of overridable methods that appears when you type the Overrides keyword (The list doesn't include methods that have already been overridden.) Figure 8-2: The DialogBoxBase form Figure 8-3: The Inheritance Picker dialog box Figure 8-4: The MyDialogBox inherited form Figure 8-5: Public properties in the base form appearing in the Properties window when you open an inherited form Notice the description of the current property, near the bottom border Figure 8-6: Forms that inherit from DataEntryFormBase automatically changing the color of the focused control Chapter 9: Object Lifetime Figure 9-1: Using the Performance utility to monitor NET memory performance counters Chapter 12: NET Basic Types Figure 12-1: The most important classes in the System namespace Chapter 13: Arrays and Collections This document is created with a trial version of CHM2PDF Pilot http://www.colorpilot.com Figure 13-1: The LinkedList and LinkedListNode generic types Chapter 14: Regular Expressions Figure 14-1: The RegexTester application, enabling you to experiment with all the most important methods and options of the Regex object Figure 14-2: Setting the ValidationExpression property of a RegularExpressionValidator ASP.NET control by selecting one of the common regular expressions you find in the Regular Expression Editor dialog box Figure 14-3: The demo application that tests the Evaluate method Figure 14-4: Using the CodeStats class to count how many statements its own source code contains Chapter 15: Files, Directories, and Streams Figure 15-1: The demo application that enables you to experiment with the FileSystemWatcher component Figure 15-2: The Security tab of the Properties dialog box (left) and the Advanced Security Settings dialog box (right) of a file Figure 15-3: The solution's Property Pages dialog box, which lets you decide which project to run when you press the F5 key Chapter 16: The My Namespace Figure 16-1: Enabling the Visual Basic application framework Figure 16-2: The Assembly Information dialog box Figure 16-3: The Copying dialog box Figure 16-4: The demo application, which parses the registry and lists all installed COM components Figure 16-5: The Resources page of the My Project designer Figure 16-6: Editing a bitmap using the built-in editor Figure 16-7: Assigning a bitmap resource to the Image property at design time Figure 16-8: Editing settings in Visual Studio 2005 Figure 16-9: Binding a setting to a property of a control Figure 16-10: Filling a Microsoft Access table with application and user settings Figure 16-11: Associating a setting with a custom settings provider Chapter 17: Assemblies and Resources Figure 17-1: The Add Reference dialog box Figure 17-2: Properties of an assembly reference Figure 17-3: A component has a code editor and a designer surface; you can display both at the same time by using the New Horizontal Tab Group command on the Window menu Figure 17-4: The Choose Toolbox Items dialog box (on the right) lets you add controls and components to the Toolbox tab that is currently visible (on the left) You can click on the Assembly Name column to quickly see all the components in a given assembly Figure 17-5: The global assembly cache as seen inside Windows Explorer Figure 17-6: The Advanced Compiler Settings dialog box Figure 17-7: The Signing page of the My Project designer and the dialog box where you define a new snk file Figure 17-8: The Assembly Information dialog box Figure 17-9: The InternalsVisibleTo attribute is recognized by C# client projects only Figure 17-10: The properties of a file, which include the action to be performed at build time (can be None, Compile, Content, or Embedded Resource) Figure 17-11: A localizable form with captions and one image, as it appears when the Language property is set to (Default) Figure 17-12: Setting the Language property to Italian Figure 17-13: The Italian version of the original form Figure 17-14: The resx resource files as they appear in the Solution Explorer window after you click the Show All Files button Figure 17-15: Creating an Italian version of the Resources.resx file Figure 17-16: The Log Options dialog box in the FUSLOGVW utility, which lets you log all binds or just failed ones, for all This document is created with a trial version of CHM2PDF Pilot http://www.colorpilot.com Figure 17-16: The Log Options dialog box in the FUSLOGVW utility, which lets you log all binds or just failed ones, for all assemblies or only those in the specified directory Figure 17-17: Adding an application to the list of configured applications with the NET Framework Configuration tool Figure 17-18: Adding an assembly to the list of configured assemblies for a specific application Chapter 18: Reflection Figure 18-1: The Reflection logical hierarchy Figure 18-2: The EventInterceptor demo application Figure 18-3: The demo application, which uses on-the-fly compilation to evaluate functions and find the roots of any equation that uses the X variable Chapter 19: Custom Attributes Figure 19-1: The application's main form Figure 19-2: The CalculatorForm, which lets you perform simple calculations Figure 19-3: The new SamplePlugin project, which extends the CalculatorForm to account for a discount percentage Figure 19-4: All the types in the DataObjectLibrary project, the core of the CAP framework Figure 19-5: Two steps in the Data Source Configuration Wizard Figure 19-6: For each DataTable in the DataSet, you can define one or more custom commands, such as FillByCustomerID Figure 19-7: Two steps of the TableAdapter Query Configuration Wizard Figure 19-8: The main form of the DemoClient project Figure 19-9: The demo application filtering customers by their country Chapter 20: Threads Figure 20-1: The Windows Task Manager utility Figure 20-2: The dialog box that NET applications display by default when an unhandled exception occurs Figure 20-3: The Debug Location toolbar, which displays the thread name and other information about the running process Figure 20-4: The Threads window, which lists all threads and lets you freeze and restart them Figure 20-5: The Breakpoint Filter dialog box Figure 20-6: The Performance utility, which lets you see several statistics regarding CLR threads Figure 20-7: The console window clearly showing that writing a space plus the thread number isn't an atomic operation Figure 20-8: A demo application using the BackgroundWorker component to search for files in the background Chapter 22: PInvoke and COM Interop Figure 22-1: The standard window that the SHFileOperation API function displays when copying files Figure 22-2: The demo program, which uses the Windows API to display the tree of all open windows Figure 22-3: The Runtime Callable Wrapper object Figure 22-4: The COM tab of the Add Reference dialog box Figure 22-5: The Isolated property of an interop assembly added to the references of a project Figure 22-6: The COM Callable Wrapper object This document is created with a trial version of CHM2PDF Pilot http://www.colorpilot.com List of Tables Chapter 2: Basic Language Concepts Table 2-1: Data Types Supported Under Visual Basic 2005 and Their Corresponding NET Framework Types Chapter 4: Using Visual Studio 2005 Table 4-1: Template Parameters Chapter 6: Class Fundamentals Table 6-1: Suggested Names for Methods Alternative to Operator Overloads Chapter 8: Inheritance Table 8-1: The Effect of Class Scope and Constructor Scope on a Class's Ability to Be Instantiated or Used as a Base Class Chapter 12: NET Basic Types Table 12-1: Special Formatting Characters in Custom Formatting Strings Table 12-2: Standard Formats for Date and Time Values Table 12-3: Character Sequences That Can Be Used in Custom Date and Time Formats Chapter 14: Regular Expressions Table 14-1: The Regular Expression Language Table 14-2: Regular Expression Options Table 14-3: Common Regular Expression Patterns Chapter 15: Files, Directories, and Streams Table 15-1: Values of the FileSystemRights Enumerated Type Chapter 16: The My Namespace Table 16-1: The My.Application Object Table 16-2: Child Objects of the My.Computer Object Table 16-3: The My.User Object Chapter 17: Assemblies and Resources Table 17-1: Assembly-Level Attributes Chapter 20: Threads Table 20-1: The Possible Values for the ThreadState Property Chapter 22: PInvoke and COM Interop Table 22-1: UnmanagedType Enumerated Values This document is created with a trial version of CHM2PDF Pilot http://www.colorpilot.com Programming Microsoft Visual Basic 2005: The Language byFrancesco Balena Microsoft Press 2006 (1024 pages) ISBN:0735621837 Use this comprehensive guide to get the essential, straightforward information you need to master the core capabilities of Visual Basic 2005 Table of Contents Programming Microsoft Visual Basic 2005—The Language Introduction Part I - The Basics Chapter - Introducing the Microsoft NET Framework Chapter - Basic Language Concepts Chapter - Control Flow and Error Handling Chapter - Using Visual Studio 2005 Chapter - Debugging Visual Basic Applications Part II - Object-Oriented Programming Chapter - Class Fundamentals Chapter - Delegates and Events Chapter - Inheritance Chapter - Object Lifetime Chapter 10 - Interfaces Chapter 11 - Generics Part III - Working with the NET Framework Chapter 12 - NET Basic Types Chapter 13 - Arrays and Collections Chapter 14 - Regular Expressions Chapter 15 - Files, Directories, and Streams Chapter 16 - The My Namespace Chapter 17 - Assemblies and Resources Part IV - Advanced Topics Chapter 18 - Reflection Chapter 19 - Custom Attributes Chapter 20 - Threads Chapter 21 - Serialization Chapter 22 - PInvoke and COM Interop Index List of Figures List of Tables ... Visual Basic 6.0, Programming Microsoft Visual Basic NET, and Programming Microsoft Visual Basic NET Version 2003, as well as coauthor of Applied NET Framework Programming in Microsoft Visual Basic. .. Guidelines and Best Practices for Microsoft Visual Basic and Visual C# Developers (with Giuseppe Dimauro), all from Microsoft Press Francesco teaches Microsoft Visual Basic and C# courses in the United... switching from Visual Basic or Visual Basic NET 2003, you can simply stop at the Visual Basic and New icons, as described in the previous section Regardless of your familiarity with Visual Basic, however,

Ngày đăng: 25/03/2019, 15:02

TỪ KHÓA LIÊN QUAN