Conten Using Hashtables Cleaning Up: Remove, RemoveAt, and Clear Case Sensitivity Advanced Array Manipulation Dynamic Arrays Using Preserve 170 171 Exercises 172 Exercise 2 172 Chapter 6: building windows applications 173 Responding to Events 173 Setting Up a Button Event 174 Building a Simple Application 178 Building the Form Counting Characters Counting Words 182 Creating the Show Me! Button Code Creating More Complex Applications The Text Manipulation Project Creating the Toolbar 186 Creating the Status Ba Creating an Edit Box Clearing the Edit Box 191 Responding to Toolbar Buttons 194 Understanding Focus Using Multiple Forms 199 Summary 203 Exercises 203 Exercise 1 203 Exercise 2 203 Chapter z, Displaying dialog Boxes The MessageBox Dialog Box 205 ailable Icons for Message Box Available Buttons for MessageBox 207 Setting the Default Button 207 Miscellaneous Options 207 The show Method Syntax
xv Contents Using Hashtables 161 Cleaning Up: Remove, RemoveAt, and Clear 164 Case Sensitivity 167 Advanced Array Manipulation 168 Dynamic Arrays 168 Using Preserve 170 Summary 171 Exercises 172 Exercise 1 172 Exercise 2 172 Chapter 6: Building Windows Applications 173 Responding to Events 173 Setting Up a Button Event 174 Building a Simple Application 178 Building the Form 178 Counting Characters 180 Counting Words 182 Creating the Show Me! Button Code 185 Creating More Complex Applications 186 The Text Manipulation Project 186 Creating the Toolbar 186 Creating the Status Bar 190 Creating an Edit Box 191 Clearing the Edit Box 191 Responding to Toolbar Buttons 194 Understanding Focus 198 Using Multiple Forms 199 Help About 199 Summary 203 Exercises 203 Exercise 1 203 Exercise 2 203 Chapter 7: Displaying Dialog Boxes 205 The MessageBox Dialog Box 205 Available Icons for MessageBox 206 Available Buttons for MessageBox 207 Setting the Default Button 207 Miscellaneous Options 207 The Show Method Syntax 208 02_574019 ftoc.qxd 9/16/05 9:50 PM Page xv
Contents Example Message Bo 209 The OpenDialog Control 213 The Open FileDialog Control 213 214 The Methods of Open File Dialog 215 Using the Open File Dialog Control 216 The SaveDialog Control The Properties of Save File Dialog 220 The Methods of Save File Dialog Using the Save File Dialog Control 221 The FontDialog control 225 The Properties of FontDialog The Methods of FontDialog sing the FontDialog Control The Color Dialog Control 229 he Properties of ColorDialog 230 ing the Color Dialog Control The printDialog Control 232 he Properties of PrintDialog Using the PrintDialog Control 234 he PrintDocument Class 234 The Properties of the print Document Class 234 Printing a Document 234 The FolderBrowserDialog Control 241 242 Using the Folder BrowserDialog Control 242 How It Works 244 Exercises 246 246 Chapter 8: Creating Menus 247 Understanding Menu Features 247 Images 248 Access Keys Shortcut Keys 248 Check Marks 248 Creating Menus 250 Adding Toolbars and Controls 252 Coding Menus 254
xvi Contents Example Message Boxes 209 The OpenDialog Control 213 The OpenFileDialog Control 213 The Properties of OpenFileDialog 214 The Methods of OpenFileDialog 215 Using the OpenFileDialog Control 216 The SaveDialog Control 220 The Properties of SaveFileDialog 220 The Methods of SaveFileDialog 221 Using the SaveFileDialog Control 221 The FontDialog Control 225 The Properties of FontDialog 225 The Methods of FontDialog 226 Using the FontDialog Control 226 The ColorDialog Control 229 The Properties of ColorDialog 230 Using the ColorDialog Control 231 The PrintDialog Control 232 The Properties of PrintDialog 233 Using the PrintDialog Control 234 The PrintDocument Class 234 The Properties of the PrintDocument Class 234 Printing a Document 234 The FolderBrowserDialog Control 241 The Properties of FolderBrowserDialog 242 Using the FolderBrowserDialog Control 242 How It Works 244 Summary 245 Exercises 246 Exercise 1 246 Exercise 2 246 Chapter 8: Creating Menus 247 Understanding Menu Features 247 Images 248 Access Keys 248 Shortcut Keys 248 Check Marks 248 The Properties Window 249 Creating Menus 250 Designing the Menus 250 Adding Toolbars and Controls 252 Coding Menus 254 02_574019 ftoc.qxd 9/16/05 9:50 PM Page xvi
Conten Coding the view Menu and Toolbars 259 ur Context menus 262 Enabling and disabling Menu Items and Toolbar Buttons 270 Exercise 270 hapter 9: Debugging and Error handling 271 Major Error Typ Syntax Errors 272 Execution errors 275 Logic erro 275 Debugging 277 reating a Sample Setting Breakpoints 293 Debugging Using the Watch Window Debugging with the Locals Window Error Handling 304 Using Structured Error Handling 307 Exercises 308 Chapter 10: Buillding objects 309 Understanding objects 309 Encapsulation 311 Methods and Properties 311 31 Building classes 313 Designing an object 315 316 Storing State 317 Real Properties Read/ write Properties 323 The IsMoving Method 325 Constructors 327 vii
xvii Contents Coding the View Menu and Toolbars 259 Testing Your Code 260 Context Menus 262 Creating Context Menus 263 Enabling and Disabling Menu Items and Toolbar Buttons 266 Summary 270 Exercise 270 Chapter 9: Debugging and Error Handling 271 Major Error Types 272 Syntax Errors 272 Execution Errors 275 Logic Errors 275 Debugging 277 Creating a Sample Project 277 Setting Breakpoints 293 Debugging Using the Watch Window 300 Debugging with the Locals Window 302 Error Handling 304 Using Structured Error Handling 305 Summary 307 Exercises 308 Exercise 1 308 Exercise 2 308 Chapter 10: Building Objects 309 Understanding Objects 309 Encapsulation 311 Methods and Properties 311 Events 311 Visibility 312 What Is a Class? 313 Building Classes 313 Reusability 314 Designing an Object 315 State 316 Behavior 316 Storing State 317 Real Properties 319 Read/Write Properties 323 The IsMoving Method 325 Constructors 327 02_574019 ftoc.qxd 9/16/05 9:50 PM Page xvii
Contents Creating a Constructor Inheritance 329 Adding New Methods and Properties Adding a GetPower ToWeight Ratio Method Changing Defaults Polymorphism: Scary Word, Simple Concept 336 Overriding More Methods Inheriting from the Object Class 339 objects and structures The framework classes 340 Namespaces s Statement Creating Your Own Namespace Inheritance in the. nEt Framework 345 346 excises 346 Exercise 2 Chapter 11: Advanced object-Oriented Techniques 47 Building a Favorites viewer 347 Internet shortcuts and Favorites 348 Using Classes Scanning Favorite Viewing Favorites 363 An Alternative Favorite viewer Building a Favorites Tray How It Works Using shared Properties and Methods 371 Using Shared Procedures Using Shared Method 376 Understanding object-Oriented Programming and Memory Management 378 379 Releasing Resources 380 Defragmentation and Compaction 382
xviii Contents Creating a Constructor 327 Inheritance 329 Adding New Methods and Properties 331 Adding a GetPowerToWeightRatio Method 333 Changing Defaults 335 Polymorphism: Scary Word, Simple Concept 336 Overriding More Methods 337 Inheriting from the Object Class 339 Objects and Structures 340 The Framework Classes 340 Namespaces 341 The Imports Statement 343 Creating Your Own Namespace 343 Inheritance in the .NET Framework 345 Summary 346 Exercises 346 Exercise 1 346 Exercise 2 346 Chapter 11: Advanced Object-Oriented Techniques 347 Building a Favorites Viewer 347 Internet Shortcuts and Favorites 348 Using Classes 350 Scanning Favorites 355 Viewing Favorites 363 An Alternative Favorite Viewer 365 Building a Favorites Tray 365 How It Works 368 Displaying Favorites 368 Using Shared Properties and Methods 371 Using Shared Procedures 372 Using Shared Methods 376 Understanding Object-Oriented Programming and Memory Management 378 Garbage Collection 379 Releasing Resources 380 Defragmentation and Compaction 381 Summary 382 Exercise 382 02_574019 ftoc.qxd 9/16/05 9:50 PM Page xviii
Conten Chapter 12: Building class Libraries 383 Understanding class Libraries 384 Creating a Class Library 384 Building a Class Library for Favorites viewer A Multitiered Application Using Strong Names 389 Signing Assemblies Assembly Versions 392 Registering Assemblies Gacutil Utility Why Is My Assembly Not Visible in the References Dialog Box? 393 Designing Class Libraries Using Third-Party class libraries 396 Using InternetFavorites dll Viewing Classes with the Object Browser 397 Summary Exercise Chapter 13: Creating Your Own Custom Controls 399 Windows forms controls Creating and Testing a User Control 400 Exposing Properties from User Controls 404 Adding Properties 404 Exposing Methods from User Controls Exposing Events from User Controls 406 Design Time or Run Time 411 Creating a Form Library 413 Building the Form Library Project Login Form 413 Testing the FormsLibrary Hooking Up the events 422 Summary Exercise 42 Chapter 14: Programming custom Graphics 427 Building a Simple Paint Program 427 Creating a Project with User Controls 428 How Drawing Programs Work Raster Graphics Vector Graphics 429
xix Contents Chapter 12: Building Class Libraries 383 Understanding Class Libraries 384 Creating a Class Library 384 Building a Class Library for Favorites Viewer 386 A Multitiered Application 388 Using Strong Names 389 Signing Assemblies 390 Assembly Versions 392 Registering Assemblies 392 Gacutil Utility 393 Why Is My Assembly Not Visible in the References Dialog Box? 393 Designing Class Libraries 395 Using Third-Party Class Libraries 396 Using InternetFavorites.dll 396 Viewing Classes with the Object Browser 397 Summary 398 Exercise 398 Chapter 13: Creating Your Own Custom Controls 399 Windows Forms Controls 400 Creating and Testing a User Control 400 Exposing Properties from User Controls 404 Adding Properties 404 Exposing Methods from User Controls 405 Exposing Events from User Controls 406 Design Time or Run Time 411 Creating a Form Library 413 Building the Form Library Project Login Form 413 Testing the FormsLibrary 420 Hooking Up the Events 422 Summary 425 Exercise 426 Chapter 14: Programming Custom Graphics 427 Building a Simple Paint Program 427 Creating a Project with User Controls 428 How Drawing Programs Work 428 Raster Graphics 428 Vector Graphics 429 02_574019 ftoc.qxd 9/16/05 9:50 PM Page xix