| About This Book | xv |
| CHAPTER 1 Introduction to the .NET Framework | 1 |
| About This Chapter | 1 |
| Before You Begin | 1 |
| Lesson 1: The .NET Framework and the Common Language Runtime | 2 |
| Overview of the .NET Framework | 2 |
| Languages and the .NET Framework | 2 |
| The Structure of a .NET Application | 3 |
| Compilation and Execution of a .NET Application | 4 |
| Lesson Summary | 5 |
| Lesson 2: The .NET Base Class Library | 6 |
| Reference Types and Value Types | 8 |
| Using .NET Framework Types in Your Application | 9 |
| The Imports and Using Statements | 12 |
| Referencing External Libraries | 13 |
| Lesson Summary | 14 |
| Lesson 3: Using Classes and Structures | 15 |
| Members | 15 |
| Creating Classes | 16 |
| Creating Structures | 16 |
| Adding Members | 16 |
| Nested Types | 17 |
| Instantiating User-Defined Types | 18 |
| Classes vs. Structures | 19 |
| Lesson Summary | 19 |
| Lesson 4: Using Methods | 20 |
| Adding Methods | 20 |
| Calling Methods | 21 |
| Method Variables | 21 |
| Parameters | 22 |
| Constructors and Destructors | 25 |
| Lesson Summary | 26 |
| Lesson 5: Scope and Access Levels | 27 |
| Member Access Modifiers | 27 |
| Type Access Modifiers | 29 |
| Access Modifiers for Nested Types | 30 |
| Shared (static) Members | 30 |
| Lesson Summary | 32 |
| Lesson 6: Garbage Collection | 33 |
| Circular References | 34 |
| Lesson Summary | 35 |
| Lab 1: Classes and Garbage Collection | 36 |
| Before You Begin | 36 |
| Exercise 1.1: Making the Demo Class | 36 |
| Exercise 1.2: Demonstrating Garbage Collection | 37 |
| Review | 39 |
| CHAPTER 2 Creating the User Interface | 41 |
| About This Chapter | 41 |
| Before You Begin | 41 |
| Lesson 1: User Interface Design Principles | 42 |
| Forms, Controls, and Menus | 43 |
| Composition | 44 |
| Simplicity | 44 |
| Position of Controls | 45 |
| Consistency | 45 |
| Aesthetics | 45 |
| Lesson Summary | 47 |
| Lesson 2: Using Forms | 48 |
| Adding Forms to Your Project | 48 |
| Visual Inheritance | 49 |
| Setting the Start-Up Form | 50 |
| Setting the Start-Up Location | 52 |
| Changing the Appearance of Your Form | 53 |
| BackColor, ForeColor, and Text Properties | 54 |
| Font, Cursor, and BackGroundImage | 54 |
| Opacity | 54 |
| Using Form Methods | 55 |
| Show and ShowDialog | 56 |
| Activate | 56 |
| Hide | 57 |
| Close | 57 |
| Using Form Events | 57 |
| Event Arguments | 59 |
| Form Lifetime Events | 60 |
| Lesson Summary | 62 |
| Lesson 3: Using Controls and Components | 64 |
| Working with Controls | 64 |
| Setting the Control Tab Order | 66 |
| Controls That Can Contain Other Controls | 67 |
| Docking and Anchoring Controls | 68 |
| Using the Controls Collection | 71 |
| Adding Controls to the Toolbox | 72 |
| Creating Event Handlers for Controls | 73 |
| Interacting with the Mouse | 74 |
| Using Extender Provider Components | 76 |
| Lesson Summary | 77 |
| Lesson 4: Using Menus | 78 |
| Creating Menus During Design | 78 |
| Using the MainMenu Component | 78 |
| Separating Menu Items | 80 |
| Menu Access and Shortcut Keys | 80 |
| Using Menu Item Events | 81 |
| Creating Context Menus | 82 |
| Modifying Menus at Run Time | 82 |
| Enabling and Disabling Menu Commands | 82 |
| Displaying Check Marks on Menu Items | 83 |
| Displaying Radio Buttons on Menu Items | 83 |
| Making Menu Items Invisible | 83 |
| Cloning Menus | 84 |
| Merging Menus at Run Time | 84 |
| Adding Menu Items at Run Time | 85 |
| Lesson Summary | 86 |
| Lesson 5: Validating User Input | 87 |
| Field-Level Validation | 87 |
| Using Events in Field-Level Validation | 88 |
| Handling the Focus | 91 |
| Form-Level Validation | 93 |
| Providing User Feedback | 95 |
| Lesson Summary | 98 |
| Lab 2: The Virtual Doughnut Factory | 99 |
| Before You Begin | 99 |
| Exercise 2.1: Creating the User Interface | 99 |
| Exercise 2.2: Adding a Menu | 103 |
| Exercise 2.3: Creating Validation Handlers | 104 |
| Review | 107 |
| CHAPTER 3 Types and Members | 109 |
| About This Chapter | 109 |
| Before You Begin | 109 |
| Lesson 1: Using Data Types | 110 |
| The .NET Data Types | 110 |
| Converting Types | 113 |
| Using Data Type Functionality | 116 |
| Lesson Summary | 119 |
| Lesson 2: Using Constants, Enums, Arrays, and Collections | 120 |
| Constants and Enumerations | 120 |
| Arrays | 124 |
| Multidimensional Arrays | 126 |
| Collections | 128 |
| Enumerating the Members of an Array or a Collection | 131 |
| Lesson Summary | 133 |
| Lesson 3: Implementing Properties | 134 |
| Implementing Properties | 134 |
| Read-Only and Write-Only Properties | 137 |
| Parameterized Properties | 138 |
| Default Properties and Indexers | 139 |
| Collection Properties | 140 |
| Lesson Summary | 142 |
| Lesson 4: Implementing Delegates and Events | 144 |
| Delegates | 144 |
| Declaring and Raising Events | 146 |
| Implementing Event Handlers | 147 |
| Event Handlers That Handle Multiple Events | 149 |
| Events with Multiple Handlers | 149 |
| Removing Handlers at Run Time | 150 |
| Lesson Summary | 151 |
| Lab 3-1: Adding Components and Implementing Members | 152 |
| Before You Begin | 152 |
| Exercise 3.1: Creating the DoughnutMachine Component | 152 |
| Exercise 3.2: Adding the DoughnutMachine to the User Interface | 159 |
| Lab 3-2: Creating a Class | 164 |
| Before You Begin | 164 |
| Exercise 3.3: Creating the Fraction Class | 164 |
| Exercise 3.4: Testing the Fraction Class | 167 |
| Review | 170 |
| CHAPTER 4 Object-Oriented Programming and Polymorphism | 171 |
| About This Chapter | 171 |
| Before You Begin | 171 |
| Lesson 1: Introduction to Object-Oriented Programming | 172 |
| Objects, Members, and Abstraction | 172 |
| Encapsulation | 174 |
| Polymorphism | 174 |
| Lesson Summary | 175 |
| Lesson 2: Overloading Members | 177 |
| Creating Overloading Methods | 178 |
| Overloading Operators with Visual C# | 179 |
| Lesson Summary | 181 |
| Lesson 3: Interface Polymorphism | 182 |
| Defining Interfaces | 182 |
| Polymorphism with Interfaces | 184 |
| Implementing Interfaces | 185 |
| Lesson Summary | 188 |
| Lesson 4: Inheritance Polymorphism | 190 |
| Inheritance | 190 |
| Inherited Members | 192 |
| Abstract Classes and Members | 199 |
| Lesson Summary | 202 |
| Lab 4: Using Inherited Classes | 203 |
| Before You Begin | 203 |
| Exercise 4.1: Creating the CompoundFraction Class | 203 |
| Exercise 4.2: Creating Overloaded Operators or Shared Methods | 208 |
| Exercise 4.3: Creating a Strongly Typed Collection Class | 209 |
| Review | 215 |
| CHAPTER 5 Testing and Debugging Your Application | 217 |
| About This Chapter | 217 |
| Before You Begin | 217 |
| Lesson 1: Using the Debugging Tools | 218 |
| Types of Errors | 218 |
| Break Mode | 220 |
| Setting Breakpoints | 223 |
| Breakpoint Properties and Setting Breakpoint Conditions | 225 |
| Using the Debugging Windows | 226 |
| Lesson Summary | 230 |
| Lesson 2: Using the Debug and Trace Classes | 231 |
| How Tracing Works | 231 |
| Writing Trace and Debug Output | 232 |
| The Listeners Collection | 233 |
| Using Trace Switches | 236 |
| Configuring Trace Switches | 238 |
| Lesson Summary | 240 |
| Lesson 3: Creating a Unit Test Plan | 241 |
| The Unit Test Plan | 241 |
| Lesson Summary | 245 |
| Lesson 4: Handling and Throwing Exceptions | 246 |
| How Exceptions Are Handled | 246 |
| Creating an Exception Handler | 247 |
| Throwing Exceptions | 251 |
| Lesson Summary | 255 |
| Lab 5-1: Debugging an Application | 256 |
| Before You Begin | 256 |
| Exercise 5-1.1: Identifying Syntax Errors | 256 |
| Exercise 5-1.2: Identifying Run-Time Errors | 257 |
| Exercise 5-1.3: Identifying Logical Errors | 258 |
| Lab 5-2: Creating, Throwing, and Handling Exceptions | 260 |
| Before You Begin | 260 |
| Exercise 5-2.1: Creating the MyDivideByZeroException class | 260 |
| Exercise 5-2.2: Raising Exceptions | 261 |
| Exercise 5-2.3: Handling Exceptions | 262 |
| Lab 5-3: Implementing Tracing | 264 |
| Before You Begin | 264 |
| Exercise 5-3.1: Adding Trace Functionality | 264 |
| Exercise 5-3.2: Creating a .config File and Testing Tracing | 265 |
| Review | 267 |
| CHAPTER 6 Data Access Using ADO.NET | 269 |
| About This Chapter | 269 |
| Before You Begin | 269 |
| Lesson 1: Overview of ADO.NET | 270 |
| Disconnected Database Access | 270 |
| ADO.NET Data Architecture | 271 |
| Lesson Summary | 274 |
| Lesson 2: Overview of Structured Query Language | 275 |
| The SELECT Statement | 275 |
| The DELETE Statement | 278 |
| The UPDATE Statement | 278 |
| The INSERT INTO Statement | 279 |
| Lesson Summary | 279 |
| Lesson 3: Accessing Data | 281 |
| Connecting to a Database | 281 |
| Using Data Commands | 284 |
| Using DataReaders | 290 |
| Creating and Configuring DataAdapters | 297 |
| Retrieving Data Using DataAdapters | 300 |
| Lesson Summary | 305 |
| Lesson 4: Using DataSet Objects and Updating Data | 306 |
| Creating and Filling DataSet Objects Without a DataAdapter | 306 |
| DataRelation Objects | 311 |
| Constraints | 312 |
| Editing and Updating Data | 315 |
| Lesson Summary | 322 |
| Lesson 5: Binding, Viewing, and Filtering Data | 323 |
| Data Binding | 323 |
| Filtering and Sorting Data | 331 |
| Lesson Summary | 336 |
| Lesson 6: Using XML in ADO.NET | 337 |
| Retrieving XML from a SQL Server 2000 Database | 337 |
| Using XML with DataSets | 338 |
| Using the XmlDataDocument Class | 340 |
| Lesson Summary | 343 |
| Lab 6-1: Connecting with a Database | 345 |
| Before You Begin | 345 |
| Exercise 6-1.1: Adding Data Access and Using the DataReader | 345 |
| Exercise 6-1.2: Retrieving and Updating Data Using DataAdapter Objects and a DataSet | 347 |
| Exercise 6-1.3: Creating a Typed DataSet Using the XML Designer | 349 |
| Exercise 6-1.4: Using the Data Form Wizard | 351 |
| Lab 6-2: Connecting with an XML Data Store | 354 |
| Before You Begin | 354 |
| Exercise 6-2.1: Accessing the XML Data Store | 354 |
| Review | 357 |
| CHAPTER 7 Creating Controls Using the .NET Framework | 359 |
| About This Chapter | 359 |
| Before You Begin | 359 |
| Lesson 1: Using GDI+ | 360 |
| The System.Drawing Namespaces | 360 |
| The Graphics Object | 361 |
| Color, Brushes, and Pens | 365 |
| Rendering Simple Shapes | 368 |
| Rendering Text | 369 |
| Rendering Complex Shapes | 370 |
| Lesson Summary | 373 |
| Lesson 2: Authoring Controls | 374 |
| Overview of Control Authoring | 374 |
| Creating an Inherited Control | 377 |
| Creating a User Control | 379 |
| Creating a Custom Control | 382 |
| Lesson Summary | 383 |
| Lesson 3: Common Tasks Using Controls | 385 |
| Adding Your Control to the Toolbox | 385 |
| Providing a Toolbox Bitmap for Your Control | 386 |
| Debugging Your Control | 387 |
| Managing Control Licensing | 388 |
| Hosting Your Control in Internet Explorer | 390 |
| Lesson Summary | 391 |
| Lab 7: Creating a Custom Control | 392 |
| Before You Begin | 392 |
| Exercise 7.1: Creating the Control | 392 |
| Exercise 7.2: Testing Your Control | 397 |
| Review | 399 |
| CHAPTER 8 Advanced .NET Framework Topics | 401 |
| About This Chapter | 401 |
| Before You Begin | 401 |
| Lesson 1: Implementing Print Functionality | 402 |
| The PrintDocument Component | 402 |
| Printing Content | 405 |
| Using PrintPreviewControl | 411 |
| Configuring Printing | 412 |
| Lesson Summary | 415 |
| Lesson 2: Accessing and Invoking Components | 417 |
| Accessing .NET and COM Type Libraries | 417 |
| Instantiating ActiveX Controls | 419 |
| Accessing a Web Service | 419 |
| Accessing the Windows API | 424 |
| Lesson Summary | 425 |
| Lesson 3: Implementing Accessibility | 427 |
| Accessibility Design | 427 |
| Accessibility and the Certified for Windows Program | 428 |
| Accessibility Properties of Windows Forms Controls | 429 |
| Lesson Summary | 430 |
| Lesson 4: Implementing Help in Your Application | 431 |
| The Help Class | 431 |
| The HelpProvider Component | 432 |
| Lesson Summary | 433 |
| Lesson 5: Globalization and Localization | 434 |
| Globalization and Localization | 434 |
| Culture-Specific Formatting | 439 |
| Lesson Summary | 443 |
| Lab 8: Creating a Localized Form with Print Support | 445 |
| Before You Begin | 445 |
| Exercise 8.1: Creating the Form | 445 |
| Exercise 8.2: Localizing the Form | 448 |
| Exercise 8.3: Adding Print Support | 451 |
| Review | 454 |
| CHAPTER 9 Assemblies, Configuration, and Security | 455 |
| About This Chapter | 455 |
| Before You Begin | 455 |
| Lesson 1: Assemblies and Resources | 456 |
| Assemblies | 456 |
| Resources and Resource Assemblies | 458 |
| Shared Assemblies | 465 |
| Lesson Summary | 467 |
| Lesson 2: Configuring and Optimizing Your Application | 469 |
| Creating the Configuration File | 469 |
| Configuring Your Application Using Dynamic Properties | 471 |
| Optimizing Your Application's Performance | 475 |
| Lesson Summary | 477 |
| Lesson 3: Securing Your Application | 478 |
| Permissions | 479 |
| Configuring Role-Based Authorization | 479 |
| Configuring Code Access Security | 484 |
| Using Exception Handling with Imperative Security | 490 |
| Configuring Network and Machine Code Access Security Policy | 491 |
| Lesson Summary | 494 |
| Lab 9: Configuring and Securing an Application | 495 |
| Before You Begin | 495 |
| Exercise 9.1: Adding the Configuration File | 495 |
| Exercise 9.2: Securing Your Application | 497 |
| Review | 500 |
| CHAPTER 10 Deploying Your Application | 501 |
| About This Chapter | 501 |
| Before You Begin | 501 |
| Lesson 1: Planning the Deployment of Your Project | 502 |
| XCOPY Deployment | 502 |
| Creating Setup Projects | 503 |
| Configuring Build Properties of Your Setup Project | 507 |
| Building, Distributing, and Deploying a Setup Project | 511 |
| Lesson Summary | 514 |
| Lesson 2: Configuring Your Setup Project | 515 |
| Setting the Setup Project Properties | 515 |
| The Installation Editors | 517 |
| Installing a Native Assembly Image | 529 |
| Verifying Installed Assembly Security Policies | 529 |
| Lesson Summary | 530 |
| Lab 10: Creating an Installer Application | 531 |
| Before You Begin | 531 |
| Exercise 10.1: Creating the Setup Project | 531 |
| Exercise 10.2: Configuring Your Application | 532 |
| Exercise 10.3: Installing Your Application | 532 |
| Review | 534 |
| APPENDIX A Questions and Answers | 535 |
| GLOSSARY | 549 |
| INDEX | 557 |