| Acknowledgments | xv |
| Introduction | xvii |
Chapter 1 | Getting Started with Your First Windows Program | 1 |
| Obtaining and Installing Visual C# 2005 | 2 |
| System Requirements | 2 |
| Choosing the Right Version | 3 |
| Installing Visual C# 2005 | 4 |
| Starting Your First Visual C# 2005 Project | 4 |
| Starting the Program | 5 |
| Specifying the Type of New Project | 6 |
| Specifying the Name and Location of the Project | 7 |
| Integrated Development Environment (IDE) | 8 |
| Run the Project! | 9 |
| What Is a Computer Program? | 11 |
| What Is a Programming Language? | 13 |
| Translating the Code for the Computer | 14 |
| Conclusion | 14 |
| Quiz | 15 |
Chapter 2 | Writing Your First Code | 17 |
| Starting an Existing Project | 18 |
| Design View and Code View | 20 |
| Object Browser | 20 |
| Classes and Objects | 25 |
| Inherits | 25 |
| Namespaces | 25 |
| .NET Framework | 26 |
| Properties | 27 |
| Properties Window | 27 |
| Changing Properties at Design Time | 28 |
| What Is a Windows Application? | 29 |
| Windows Applications Are Gooey | 30 |
| Windows Applications Are Event-Driven | 33 |
| Classes Have Events | 34 |
| Creating an Event Procedure | 34 |
| Creating an Event Procedure Stub | 35 |
| Writing Code Inside the Event Procedure | 37 |
| Conclusion | 40 |
| Quiz | 41 |
Chapter 3 | Controls | 43 |
| Adding Controls to the Form | 44 |
| Toolbox | 44 |
| Copying a Control from the Toolbox to the Form | 45 |
| Changing the Control's Location | 47 |
| Changing the Control's Size | 49 |
| Important Label Properties | 50 |
| Text Property | 50 |
| Name Property | 51 |
| The Label Control in Action | 52 |
| Mouse Coordinates | 52 |
| Creating the Application | 53 |
| How the Code Works | 54 |
| Using Event Procedure Parameters | 56 |
| What If You Type the Wrong Code? | 56 |
| ToString Method | 58 |
| Delegate | 59 |
| Conclusion | 60 |
| Quiz | 61 |
Chapter 4 | Storing Information-Data Types and Variables | 63 |
| Data Types | 64 |
| Numeric Data Types | 65 |
| Text Data Types | 65 |
| Data Types of Visual C# Properties | 66 |
| Variables | 68 |
| Declaring a Variable | 68 |
| Where Do I Declare a Variable? | 71 |
| Constants | 74 |
| Declaring a Constant | 75 |
| Why Use Constants? | 76 |
| Conclusion | 77 |
| Quiz | 78 |
Chapter 5 | Letting the Program Do the Math-Arithmetic Operators | 79 |
| Arithmetic Operators | 80 |
| The Addition Operator | 80 |
| The Subtraction Operator | 81 |
| The Multiplication Operator | 81 |
| The Division Operators | 81 |
| Operator Precedence | 82 |
| Combining Arithmetic and Assignment Operators | 83 |
| Increment and Decrement Operators | 84 |
| The Parse Method | 85 |
| Class Methods | 86 |
| Change Machine Project | 86 |
| Creating the Project | 87 |
| The Algorithm | 89 |
| Conclusion | 91 |
| Quiz | 92 |
Chapter 6 | Making Comparisons-Comparison and Logical Operators | 93 |
| Debugging | 94 |
| Comparison Operators | 96 |
| Numeric Comparison Operators | 96 |
| String Comparisons | 98 |
| Precedence | 99 |
| Logical Operators | 99 |
| The && Operator | 100 |
| The & Operator | 101 |
| The [double vertical line] Operator | 101 |
| The [vertical bar] Operator | 102 |
| The ^ Operator | 102 |
| The ! Operator | 103 |
| Precedence | 104 |
| Why && and [double vertical line] in Addition to & and [vertical bar]? | 104 |
| Conclusion | 105 |
| Quiz | 105 |
Chapter 7 | Making Choices-if and switch Control Structures | 107 |
| Creating a Test Project | 108 |
| The if Control Structure | 108 |
| The if Statement | 109 |
| The if ... else Statement | 113 |
| The if ... else if Statement | 116 |
| Input Validation | 117 |
| Exceptions | 118 |
| Controls Used for the if Control Structure | 122 |
| CheckBox Control | 122 |
| RadioButton Control | 123 |
| Pizza Calculator | 124 |
| Creating the Project | 125 |
| How the Project Works | 125 |
| The Code | 125 |
| The switch Control Structure | 128 |
| Syntax | 128 |
| The switch Control Structure in Action | 129 |
| The break Keyword | 131 |
| Choosing Between if ... else if and switch | 132 |
| Conclusion | 132 |
| Quiz | 133 |
Chapter 8 | Repeating Yourself-Loops and Arrays | 135 |
| Loops | 136 |
| The for Statement | 136 |
| The continue Keyword | 144 |
| The foreach Statement | 147 |
| The while Statement | 147 |
| The do while construct | 150 |
| Arrays | 150 |
| Declaring Arrays | 150 |
| Assigning Values to the Array | 151 |
| Conclusion | 153 |
| Quiz | 154 |
Chapter 9 | Organizing Your Code with Methods | 155 |
| Defining and Calling a Method | 156 |
| Terminology of a Method | 156 |
| Naming a Method | 158 |
| Defining a Method | 158 |
| Calling a Method | 159 |
| Parameters-Sending Information to a Method | 161 |
| Passing Arguments by Value | 161 |
| Passing Arguments by Reference | 164 |
| Returning a Value from a Method | 169 |
| Syntax | 169 |
| How the Value Is Returned | 170 |
| Saving the Return Value | 170 |
| Returning a Boolean Value | 171 |
| Conclusion | 172 |
| Quiz | 173 |
Chapter 10 | Helper Forms | 175 |
| Message Boxes | 176 |
| Creating the Project | 177 |
| Message Boxes Are Modal | 178 |
| Show Method | 178 |
| Using the Show Method's Return Value | 182 |
| Dialog Forms | 184 |
| Creating the Project | 184 |
| Showing the Dialog Form and Returning Its Result | 188 |
| Accessing Values from the Dialog Form | 190 |
| Modal vs. Modeless | 190 |
| Conclusion | 191 |
| Quiz | 192 |
Chapter 11 | Menus | 193 |
| Creating a Main Menu | 194 |
| Adding a MenuStrip Control to a Form | 195 |
| Adding Menu Items to the MenuStrip | 196 |
| Enhancing the Menu Items | 201 |
| Adding Functionality to the Menu Items | 203 |
| Disabling Menu Items | 204 |
| Creating a Context Menu | 205 |
| Adding a ContextMenuStrip to a Form | 205 |
| Adding Menu Items to the ContextMenuStrip | 207 |
| Adding Functionality to Context Menu Items | 210 |
| Text Editor Project | 212 |
| Creating the Project | 212 |
| Explanation of the Code | 214 |
| Conclusion | 215 |
| Quiz | 215 |
Chapter 12 | Toolbars | 217 |
| Creating a Toolbar | 218 |
| Adding a Toolbar to a Form | 218 |
| Adding Buttons to the Toolbar | 219 |
| Associating Images with Toolbar Buttons | 221 |
| Associating Code with Clicks of Toolbar Buttons | 229 |
| Conclusion | 230 |
| Quiz | 231 |
Chapter 13 | Accessing Text Files | 233 |
| Open and Save File Dialog Boxes | 234 |
| Adding an OpenFileDialog Control to Your Form | 234 |
| Showing the OpenFileDialog Control | 235 |
| Determining Whether Open or Cancel Is Chosen | 236 |
| Identifying the File to Open | 237 |
| SaveFileDialog Class | 238 |
| Reading from a Text File | 240 |
| StreamReader Class | 240 |
| Reading the Text File into the TextBox | 242 |
| Closing the Text File | 243 |
| Writing to a Text File | 244 |
| StreamWriter Class | 244 |
| Writing from the TextBox to the Text File | 245 |
| Closing the Text File | 246 |
| Conclusion | 247 |
| Quiz | 247 |
Chapter 14 | Databases | 249 |
| Installing the Database | 250 |
| Obtaining the Northwind Traders Database | 250 |
| Installing the Northwind Traders Database | 250 |
| Connecting to the Database | 251 |
| Using Server Explorer | 254 |
| Exploring the Database | 255 |
| Exploring the Customers Table | 256 |
| Database Project | 258 |
| What the Project Does | 258 |
| Creating the Form | 259 |
| Importing Data Namespaces | 260 |
| Creating a Connection | 260 |
| Creating a Command | 263 |
| Filling the DataGridView | 265 |
| Conclusion | 269 |
| Quiz | 270 |
Chapter 15 | Web Applications | 271 |
| ASP.NET | 272 |
| Internet Information Services | 272 |
| Determining If IIS Is Already Installed | 273 |
| Installing IIS | 274 |
| Starting the IIS Admin Service | 274 |
| Starting the Default Website | 276 |
| URL | 278 |
| Your Computer as the Web Server | 278 |
| Virtual and Physical Paths | 279 |
| Creating a Web Application | 280 |
| ASP.NET Development Server | 281 |
| ASP.NET Application IDE | 284 |
| Creating a Database Web Application | 286 |
| Adding a GridView Control | 286 |
| Locating the Database on the Web Server | 288 |
| Adding Code | 290 |
| Conclusion | 292 |
| Quiz | 292 |
| Final Exam | 293 |
| Answers | 299 |
| Index | 315 |