INTRODUCTION xxvii CHAPTER 1: WELCOME TO VISUAL BASIC 2012 1 Event-Driven Programming 2 Installing Visual Basic 2012 3 The Visual Studio 2012 IDE 6 The Profile Setup Page 6 The Menu 7 The Toolbars 8 Creating a Simple Application 9 Windows in the Visual Studio 2012 IDE 10 The Toolbox 14 Modified Hungarian Notation 17 The Code Editor 18 Using the Help System 23 Summary 23 CHAPTER 2: THE MICROSOFT .NET FRAMEWORK 27 Microsoft''s Reliance on Windows 28 MSN 1.0 28 The .NET Vision 29 This Sounds Like Java 30 Where Now? 30 Writing Software for Windows 31 The .NET Framework Classes 32 Executing Code 33 Common Language Runtime 34 Code Loading and Execution 35 Application Isolation 35 Security 35 Interoperability 36 Exception Handling 36 The Common Type System and Common Language Specification 37 Summary 37 CHAPTER 3: WRITING SOFTWARE 41 Information and Data 41 Algorithms 42 What Is a Programming Language? 43 Working with Variables 44 Comments and Whitespace 46 Comments 47 Whitespace 48 Data Types 49 Working with Numbers 49 Common Integer Math Operations 50 Integer Math Shorthand 52 The Problem with Integer Math 54 Floating-Point Math 54 Other States 56 Single-Precision Floating-Point Numbers 56 Working with Strings 57 Concatenation 58 Using the Concatenation Operator Inline 59 More String Operations 59 Substrings 61 Formatting Strings 62 Localized Formatting 63 Replacing Substrings 64 Using Dates 65 Formatting Date Strings 66 Extracting Date Properties 67 Date Constants 68 Defining Date Literals 69 Manipulating Dates 70 Boolean 71 Storing Variables 71 Binary 71 Bits and Bytes 72 Representing Values 73 Converting Values 74 Methods 76 Why Use Methods? 76 Methods You''ve Already Seen 77 Building a Method 80 Choosing Method Names 83 Scope 84 Summary 86 CHAPTER 4: CONTROLLING THE FLOW 89 Making Decisions 89 The If Statement 90 The Else Statement 92 Allowing Multiple Alternatives with ElseIf 92 Nested If Statements 94 Single-Line If Statement 94 Comparison Operators 94 Using Not Equal To 94 Using the Numeric Operators 96 The And and Or Operators 99 Using the And Operator 101 More on And and Or 102 String Comparison 103 Select Case 104 Case-Insensitive Select Case 108 Multiple Selections 110 The Case Else Statement 112 Different Data Types with Select Case 112 Loops 113 The For.Next Loop 113 Using the Step Keyword 116 Looping Backward 117 The For Each.Next Loop 118 The Do.Loop Loops 119 Do While.
Loop 121 Acceptable Expressions for a Do.Loop 123 Other Versions of the Do.Loop 123 Nested Loops 124 Quitting Early 126 Quitting Do.Loops 128 Infinite Loops 129 Summary 130 CHAPTER 5: WORKING WITH DATA STRUCTURES 133 Understanding Arrays 134 Defining and Using Arrays 134 Using For Each.Next 137 Passing Arrays As Parameters 139 Sorting Arrays 141 Going Backward 142 Initializing Arrays with Values 144 Understanding Enumerations 145 Using Enumerations 145 Determining the State 149 Setting Invalid Values 151 Understanding Constants 152 Using Constants 152 Different Constant Types 154 Structures 155 Building Structures 155 Adding Properties to Structures 158 Working with ArrayLists 159 Using an ArrayList 159 Deleting from an ArrayList 163 Showing Items in the ArrayList 166 Working with Collections 167 Creating CustomerCollection 168 Adding an Item Property 170 Building Lookup Tables with Hashtable 171 Using Hashtables 172 Cleaning Up: Remove, RemoveAt, and Clear 175 Case Sensitivity 177 Advanced Array Manipulation 179 Dynamic Arrays 179 Using Preserve 181 Summary 182 CHAPTER 6: EXTENSIBLE APPLICATION MARKUP LANGUAGE (XAML) 185 What Is XAML? 186 XAML Syntax 187 Windows Presentation Foundation 190 Creating a Rich WPF User Interface 191 Using WPF Common Controls 197 Wiring Up Events 201 Summary 205 CHAPTER 7: BUILDING WINDOWS APPLICATIONS 209 Responding to Events 210 Building a Simple Application 217 Counting Characters 221 Counting Words 223 Creating More Complex Applications 229 Creating the Toolbar 231 Creating the Status Bar 235 Creating an Edit Box 237 Clearing the Edit Box 239 Responding to Toolbar Buttons 242 Using Multiple Forms 247 About Dialog 247 Summary 251 CHAPTER 8: DISPLAYING DIALOGS 255 The MessageBox 256 Available Icons for MessageBox 256 Available Buttons for MessageBox 257 Setting the Default Button 257 Miscellaneous Options 258 The Show Method Syntax 258 Example Message Boxes 260 The OpenFileDialog Control 263 The OpenFileDialog Control 264 The Properties of OpenFileDialog 265 OpenFileDialog Methods 266 Using the OpenFileDialog Control 266 The SaveDialog Control 271 The Properties of SaveFileDialog 271 SaveFileDialog Methods 273 Using the SaveFileDialog Control 273 The FontDialog Control 276 The Properties of FontDialog 277 The Methods of FontDialog 277 Using the FontDialog Control 277 The ColorDialog Control 280 The Properties of ColorDialog 281 Using the ColorDialog Control 282 The PrintDialog Control 283 The Properties of PrintDialog 284 Using the PrintDialog Control 285 The PrintDocument Class 285 The Properties of the PrintDocument Class 285 Printing a Document 285 The FolderBrowserDialog Control 292 The Properties of FolderBrowserDialog 292 Using the FolderBrowserDialog Control 293 Summary 296 CHAPTER 9: CREATING MENUS 299 Understanding Menu Features 299 Images 300 Access Keys 300 Shortcut Keys 300 Check Marks 300 The Properties Window 301 Creating Menus 302 Designing the Menus 302 Adding Toolbars and Controls 304 Coding Menus 306 Coding the View Menu and Toolbars 310 Testing Your Code 311 Context Menus 314 Creating Context Menus 315 Enabling and Disabling Menu Items and Toolbar Buttons 318 Summary 321 CHAPTER 10: DEBUGGING AND ERROR HANDLING 325 Major Error Types 326 Syntax Errors 326 Execution Errors 330 Logic Errors 330 Debugging 331 Creating a Sample Project 332 Setting Breakpoints 348 Debugging Using the Watch Window and QuickWatch Dialog Box 356 Debugging with the Autos Window 358 Debugging with the Locals Window 358 Error Handling 360 Using Structured Error Handling 361 Summary 363 CHAPTER 11: BUILDING OBJECTS 367 Understanding Objects 368 Encapsulation 369 Methods and Properties 369 Events 370 Visibility 370 What Is a Class? 371 Building Classes 371 Reusability 372 Designing an Object 373 State 374 Behavior 374 Storing State 375 Real Properties 378 Read/Write Properties 381 Auto-Implemented Properties 384 The IsMoving Method 384 Constructors 386 Inheritance 388 Adding New Methods and Properties 389 Adding a GetPowerToWeightRatio Method 392 Changing Defaults 394 Polymorphism: Scary Word, Simple Concept 395 Overriding More Methods 396 Inheriting from the Object Class 398 Objects and Structures 399 The Framework Classes 399 Namespaces 399 The Imports Statement 402 Creating Your Own Namespace 402 Inheritance in the .NET Framework 406 Summary 407 CHAPTER 12: ADVANCED OBJECT-ORIENTED TECHNIQUES 409 Building a Favorites Viewer 410 Internet Shortcuts and Favorites 410 Using Classes 412 Scanning Favorites 418 Viewing Favorites 426 An Alternative Favorite Viewer 428 Building a Favorites Tray 428 Displaying Favorites 429 Using Shared Properties and Methods 433 Using Shared Properties 434 Using Shared Methods 438 Understanding Object-Oriented Programming and Memory Management 439 Garbage Collection 440 Releasing Resources 441 Defragmentation and Compaction 442 Summary 443 CHAPTER 13: BUILDING CLASS LIBRARIES 445 Understanding Class Libraries 446 Creating a Class Library 446 Building a Class Library for Favorites Viewer 448 A Multitiered Application 452 Using Strong Names 453 Signing Assemblies 453 Assembly Versions 456 Registering Assemblies 456 Gacutil Utility 457 Why Is My Assembly Not Visible in the References Dialog? 457 Designing Class Libraries 457 Using Third-Party Class Libraries 459 Viewing Classes with the Object Browser 460 Summary 461 CHAPTER 14: CREATING WINDOWS FORMS USER CONTROLS 463 Wi.