Table of
Contents
Learn to Program with Visual C# 2008 Express
Chapter 1---Where Do I Begin?
Where Do We Begin
Programming the Easy Way
Planning a Program is Like Planning a House
We Receive a Call from the China Shop
We Meet with Our Client
The Systems Development Life Cycle (SDLC)
Phase 1: The Preliminary Investigation
Phase 2: Analysis
Phase 3: Design
Output Design
Input Design
Processing Design
Phase 4: Development
Phase 5: Implementation
Phase : Audit and Maintenance
Where To From Here?
Summary
Chapter 2---What Is a Computer Program?
What Is a Computer?
Data
Bits
Bytes
Memory
Computer Storage
RAM versus Storage
What Makes a Computer Program Run?
A Little Computer History
DOS
Booting DOS
Running Programs in DOS
Bad Command or File name
RAM Use in DOS
Registers
The Stack
Problems with DOS
Microsoft Windows
The Title Bar
The Menu Bar
Windows Behavior
A More In-depth Look at Windows
Virtual Memory
Multitasking
Nonpreemptive Multitasking
Preemptive Multitasking
Running Programs in Windows
Preparing the Windows Program to Run
Running the Windows Program
The Windows Handle
Windows Messages
The Focus
What Is a Computer Program?
Summary
Chapter 3---Getting Comfortable With C#
The Visual C# Environment
Preparing the Way for Programming
Let's Start Up C#!
The C# Project
The IDE
The Modes of C#
The C# Menu Bar
The File Menu
The Print Menu
The Edit Menu
The View Menu
The Project Menu
The Build Menu
The Debug Menu
The Data Menu
The Format Menu
The Tools Menu
The Window Menu
The Help Menu
The Visual C# Toolbar
The Visual C# Toolbox
The Properties Window
Summary
Chapter 4---Programming Is Easy
Less Is Best
C# Properties, Methods, and Events
C# Properties
Running the China Shop Project for the First Time
Properties of the Form
Name of the Form
Naming Conventions
Height and Width Properties
The FormBorderStyle and ControlBox Properties
The StartPosition Property
The Text Property
C# Methods
C# Events
Summary
Chapter 5---Building the User Interface
Completing the User Interface
John Smiley's Ten-Step Guide to Successful Interface Development
The C# Toolbox
The China Shop Controls
Creation of the China Shop Form
The GroupBox Control
The ListBox Control
The Label Control
The Button Control
The CheckBox Control
The RadioButton Control
The PictureBox Control
The ColorDialog Control
The Timer Control
Let's Run the China Shop Project!
Common Properties of the Controls in the China Shop Project
The Name Property
The Text Property
CheckBox Properties
Button Control Properties
The AcceptButton Property of the Form
The CancelButton Property of the Form
ColorDialog Properties
GroupBox Properties
PictureBox Control Properties
The SizeMode Property
Label Properties
The AutoSize Property
ListBox Properties
RadioButton Properties
Timer Properties
The Interval Property
Tab Order and the TabIndex Property
A Surprise Visit
Summary
Chapter 6---A First Look at Coding
Events and Event-Driven Programming
In the Old Days...
The Modern Approach
What's an Event?
An Event or an Event Procedure?
An Example of an Event Procedure Stub
The Events in the China Shop Project
The Click Event
The Load Event
The SelectedIndexChanged Event
The Tick Event
Writing Code
Program Comments
Whitespace
A C# Code Overview
The Sequence Structure—Falling Rock
The Selection Structure
The Loop Structure
The C# Debugger
The Debug/Immediate Window
Pausing a C# Program
The Break Button
Displaying Values in the Code Window
The Immediate Window
The Break Statement
The Debug Menu
Step Into
Run To Cursor
Step Over
Step Out
Set Next Statement
Show Next Statement
The Locals Window
The Watch Window
Breakpoints
Summary
Chapter 7---Data
Computer Data
Variables
Our First Variable: The Local Variable
Declaring a Variable
Assigning a Value to a Variable
Variable Scope
The Private Statement
The Public Statement
Where Should You Declare a Variable?
Must Variables Be Initialized?
Constants
C# Data Types
Numeric Data Types
sbyte
byte
short
ushort
int
uint
long and ulong
float
double
decimal
Nonnumeric Data Types
bool
char
The String Object
Property Data Types
Operations on Data
Arithmetic Operations
The Addition Operator
The Subtraction Operator
The Multiplication Operator
The Division Operator
The Modulus Operator
The Increment Operator (++)
The Decrement Operator (--)
Order of Operations
Comparison Operators
Logical Operators
The And Operator (&)
The Or Operator (|)
The Not Operator (!)
How Not to Use Not
Summary
Chapter 8---Selection Structures
Falling Rock Behavior
How Can We Improve upon This?
The C# Selection Structure---the If Statement
If…Else
If…Else…If
The Switch Statement
The China Shop Project
Reviewing the Prototype
Summary
Chapter 9---Loops
Why Loops?
The For Loop
Variations on the For Loop Theme
While Loops
The While Loop
Do-While Loop
Mr. Bullina Sends a Surprise
Summary
Chapter 10---String Manipulation
What Exactly Is a String?
String Concatenation
Breaking Strings Apart
Summary
Chapter 11---Arrays
Why Arrays?
What's an Array?
Declaring and Initializing an Array
Adding data to the Elements of an Array
The wonders of Array processing
Multiple dimensioned Arrays
Summary
Chapter 12--- File Operations
Disk File Operations
Writing Data to a Disk File
The StreamWriter Object
The WriteLine Method
The Write Method
The Close Method
Reading Data from a Disk File
The ReadLine Method
Arrays and Files
Modifying the China Shop Project to Include Arrays
Summary
Chapter 13---Finishing the User Interface
Where Are We Now?
Drop-Down Menus
A First Look at the MenuStrip Control
Adding Top-Level Menu Items
Adding Submenu Items
Deleting Menu Items
Inserting Menu Items
MenuItem Properties
Menu Item Events
Coding the Menu Item Controls
More on the MessageBox.Show Method
The Return Value of the MessageBox.Show Method
The Buttons Argument of the MessageBox.Show Method
The Icon Argument of the MessageBox.Show Method
Summary
Chapter 14---Error Handling
Common Beginner Errors
Compiler Errors
C# is Case Sensitive
Forgetting the Semicolon at the End of a Statement
Braces (and Parentheses) Must Occur in Matching Pairs
Forgetting the Left and Right Parentheses for the Condition in an If Structure
Confusing the Equality Operator (==) with the Assignment Operator (=)
Forgetting to Code a Break Statement in a Switch Structure
Runtime Errors/Logic Errors
Referring to an Element Outside the Array Bounds
Forgetting to Increment a Counter Variable
Forgetting to Add to an Accumulator
Not providing a way for a while structure to end
Failing to include the Using IO.Sys statement
Trying to Open a File For Reading That Does Not Exist
Forgetting to Close a File
Your Program Doesn't Find Any Records
Reading Too Many or Too Few Fields from a Disk File
Division by Zero
C# Error Handling
C# Exceptions
Ignore the Exception
Handle the Exception with Try-Catch-Finally Blocks
Error Handling in the China Shop Project
Summary
Chapter 15---Customizing Your Program
Writing to the Windows Registry
Registry Keys and Subkeys
Using SetValue to write to the Windows Registry
Using RegEdit
Reading from the Windows Registry
Optimizing C# Code
User-Written Procedures
Writing Our Own Procedures
Subprocedures in the China Shop Project
Testing Our Program
We Meet at the Bullina China Shop
Summary