Skip Navigation LinksLearnVisualCSharpForChristianCollegesTableofContents

Learn Visual C# for College Students

Table of Contents

 

 

1. Introduction to the Visual C# Environment

Preview 1-1
Course Objectives 1-2
What is Visual C#? 1-3
A Brief Look at Object-Oriented Programming (OOP) 1-5
Structure of a Visual C# Windows Application 1-6
Steps in Developing a Windows Application 1-8
Starting Visual C# 1-9
Visual C# Integrated Development Environment (IDE) 1-11
Saving a Visual C# Project 1-20
Drawing the User Interface 1-21
Example 1-1: Stopwatch Application - Drawing Controls 1-24
Opening a Saved Visual C# Project 1-25
Setting Properties of Controls at Design Time 1-26
Setting Properties at Run Time 1-29
How Names Are Used in Control Events 1-30
Use of Form Name Property 1-31
Example 1-2: Stopwatch Application - Setting Properties 1-33
Writing Code 1-35
Working with Event Methods 1-38
Variables 1-42
Visual C# Data Types 1-43
Variable Declaration 1-45
Arrays 1-47
Constants 1-48
Variable Initialization 1-49
Intellisense Feature 1-50
Example 1-3: Stopwatch Application - Writing Code 1-51
Class Review 1-55
Practice Problems 1 1-56
Problem 1-1. Beep Problem
Problem 1-2. Caption Problem
Problem 1-3. Enabled Problem
Problem 1-4. Date Problem
Exercise 1: Calendar/Time Display 1-57

2. The Visual C# Language

Review and Preview 2-1
A Brief History of Visual C# 2-2
Rules of C# Programming 2-3
Visual C# Statements and Expressions 2-4
Type Casting 2-6
Visual C# Arithmetic Operators 2-8
Comparison and Logical Operators 2-10
Concatenation Operators 2-12
Strings to Numbers to Strings 2-13
Visual C# String Methods 2-15
Dates and Times 2-19
Random Number Object 2-22
Math Functions 2-23
Example 2-1: Savings Account 2-25
Tab Stops and Tab Order 2-31
Example 2-2: Savings Accounts – Setting Tabs 2-34
Improving a Visual C# Application 2-35
Visual C# Decisions - if Statements 2-36
Switch - Another Way to Branch 2-40
Key Trapping 2-43
Control Focus 2-46
Example 2-3: Savings Account - Key Trapping 2-47
Visual C# Looping 2-52
Visual C# Counting 2-55
Example 2-4: Savings Account - Decisions 2-57
Class Review 2-64
Practice Problems 2 2-65
Problem 2-1. Random Number Problem
Problem 2-2. Price Problem
Problem 2-3. Odd Integers Problem
Problem 2-4. Pennies Problem
Problem 2-5. Code Problem
Exercise 2-1: Computing a Mean and Standard Deviation 2-66
Exercise 2-2: Flash Card Addition Problems 2-67

3. Object-Oriented Programming (OOP)

Review and Preview 3-1
Introduction to Object-Oriented Programming (OOP) 3-2
Objects in Visual C# 3-4
Adding a Class to a Visual C# Project 3-5
Declaring and Constructing an Object 3-8
Adding Properties to a Class 3-9
How Visual C# Puts Controls on a Form 3-11
Another Way to Add Properties to a Class 3-13
Validating Class Properties 3-16
Adding Constructors to a Class 3-19
Adding Methods to a Class 3-22
Inheritance 3-27
Example 3-1. Savings Account 3-33
Inheriting from Visual C# Controls 3-42
Building a Custom Control 3-43
Adding New Properties to a Control 3-48
Adding Control Event Methods 3-51
Example 3-2. Savings Account (Revisited) 3-54
Class Review 3-60
Practice Problems 3 3-61
Problem 3-1. Mortgage Problem
Problem 3-2. Accelerated Mortgage Problem
Problem 3-3. Flashing Label Problem
Exercise 3: Mailing List 3-63

4. Exploring the Visual C# Toolbox

Review and Preview 4-1
Method Overloading 4-2
MessageBox Dialog 4-3
Form Object 4-8
Button Control 4-11
Label Control 4-13
TextBox Control 4-15
Example 4-1: Password Validation 4-18
CheckBox Control 4-23
RadioButton Control 4-25
GroupBox Control 4-27
Panel Control 4-29
Handling Multiple Events in a Single Method 4-31
Control Arrays 4-34
Example 4-2: Pizza Order 4-36
ListBox Control 4-44
ComboBox Control 4-47
Example 4-3: Flight Planner 4-49
Class Review 4-54
Practice Problems 4 4-55
Problem 4-1. Message Box Problem
Problem 4-2. Tray Problem
Problem 4-3. List Box Problem
Problem 4-4. Combo Box Problem
Exercise 4: Customer Database Input Screen 4-56

5. More Exploration of the Visual C# Toolbox

Review and Preview 5-1
Control Z Order 5-2
NumericUpDown Control 5-3
DomainUpDown Control 5-5
Example 5-1: Date Input Device 5-8
Horizontal and Vertical ScrollBar Controls 5-12
TrackBar Control 5-15
Example 5-2: Temperature Conversion 5-17
Picture Box Control 5-22
OpenFileDialog Control 5-28
Example 5-3: Picture Box Playground 5-31
Legacy Controls 5-36
DriveListBox Control 5-38
DirListBox Control 5-39
FileListBox Control 5-40
Synchronizing the Drive, Directory, and File List Box Controls 5-42
Example 5-4: Image Viewer 5-44
Class Review 5-51
Practice Problems 5 5-52
Problem 5-1. Tic-Tac-Toe Problem
Problem 5-2. Number Guess Problem
Problem 5-3. File Times Problem
Exercise 5: Student Database Input Screen 5-53

6. Windows Application Design and Distribution

Review and Preview 6-1
Application Design Considerations 6-2
TabControl Control 6-3
Example 6-1: Shopping Cart 6-6
Using General Methods in Applications 6-22
Example 6-2: Average Value 6-25
Returning Multiple Values from General Methods 6-32
Example 6-3: Circle Geometry 6-34
MenuStrip Control 6-39
ContextMenuStrip Control 6-45
Font Object 6-46
FontDialog Control 6-48
Example 6-4: Note Editor 6-50
Distribution of a Visual C# Application 6-58
Application Icons 6-61
Visual C# Setup Wizard 6-64
Debug Versus Release Configurations 6-76
Building the Setup Program 6-77
Installing/Removing a Visual C# Application 6-78
ClickOnce Deployment 6-81
Class Review 6-82
Practice Problems 6 6-83
Problem 6-1. Tab Control Problem
Problem 6-2. Note Editor About Box Problem
Problem 6-3. Normal Numbers Problem
Problem 6-4. Context Menu Problem
Exercise 6: US/World Capitals Quiz 6-84

7. Sequential Files, Error-Handling and Debugging

Review and Preview 7-1
Sequential Files 7-2
Sequential File Output (Variables) 7-5
Application Path 7-8
Example 7-1: Writing Variables to Sequential Files 7-9
Sequential File Input (Variables) 7-13
Example 7-2: Reading Variables from Sequential Files 7-15
Parsing Data Lines 7-19
Example 7-3. Parsing Data Lines 7-21
Reading Tokenized Lines 7-25
Example 7-4. Reading Tokenized Lines 7-27
Building Data Lines 7-30
Example 7-5: Building Data Lines 7-33
Configuration Files 7-39
Example 7-6: Configuration Files 7-41
Writing and Reading Text Using Sequential Files 7-45
SaveFileDialog Control 7-48
Example 7-7: Note Editor - Reading and Saving Text Files 7-51
Error Handling 7-54
Run-Time Error Trapping and Handling 7-56
Example 7-8: Note Editor - Error Trapping 7-60
Debugging Visual C# Programs 7-62
Example 7-9: Debugging Example 7-64
Using the Debugging Tools 7-67
Debugging Strategies 7-81
Class Review 7-82
Practice Problems 7 7-83
Problem 7-1. Option Saving Problem
Problem 7-2. Text File Problem
Problem 7-3. Data File Problem
Problem 7-4. Debugging Problem
Exercise 7-1: Information Tracking 7-85
Exercise 7-2: ‘Recent Files’ Menu Option 7-86

8. Graphics Techniques with Visual C#

Review and Preview 8-1
Simple Animation 8-2
Example 8-1: Simple Animation 8-4
Timer Control 8-7
Example 8-2: Timer Control 8-9
Basic Animation 8-11
Example 8-3: Basic Animation 8-13
Random Numbers (Revisited) and Games 8-18
Example 8-4: One-Buttoned Bandit 8-20
Randomly Sorting Integers 8-28
Example 8-5: Random Integers 8-30
Graphics Methods 8-34
Graphics Object 8-35
Colors 8-37
ColorDialog Control 8-39
Pen Object 8-41
DrawLine Method 8-42
Graphics Methods (Revisted) 8-43
Persistent Graphics 8-46
Example 8-6: Drawing Lines 8-50
Rectangle Structure 8-55
DrawRectangle Method 8-57
Brush Object 8-58
FillRectangle Method 8-59
DrawEllipse Method 8-60
FillEllipse Method 8-61
Example 8-7: Drawing Rectangles and Ellipses 8-62
DrawPie Method 8-70
FillPie Method 8-72
Example 8-8: Drawing Pie Segments 8-74
Pie Charts 8-80
Line Charts and Bar Charts 8-84
Coordinate Conversions 8-87
Example 8-9: Line, Bar and Pie Charts 8-96
Class Review 8-105
Practice Problems 8 8-106
Problem 8-1. Find the Burger Game
Problem 8-2. Dice Rolling Problem
Problem 8-3. RGB Colors Problem
Problem 8-4. Plotting Problem
Problem 8-5. Pie Chart Problem
Exercise 8-1: Blackjack 8-107
Exercise 8-2: Information Tracking Plotting 8-108

9. More Graphics Methods and Multimedia Effects

Review and Preview 9-1
Mouse Events 9-2
Example 9-1: Blackboard 9-5
Persistent Graphics, Revisited (Image and Bitmap Objects) 9-14
Example 9-2: Blackboard (Revisited) 9-17
More Graphics Methods 9-20
Point Structure 9-21
DrawLines Method 9-22
DrawPolygon Method 9-24
FillPolygon Method 9-25
DrawCurve Method 9-26
DrawClosedCurve Method 9-27
FillClosedCurve Method 9-28
Example 9-3: Drawing Lines, Polygons, Curves and Closed Curves 9-30
Example 9-4: Drawing Animated Lines and Curves 9-38
HatchBrush Object 9-42
Example 9-5: Hatch Brush 9-44
LinearGradientBrush Object 9-46
Example 9-6: Linear Gradient Brush 9-48
TextureBrush Object 9-50
Example 9-7: Texture Brush 9-51
DrawString Method 9-53
Multimedia Effects 9-59
Animation with DrawImage Method 9-60
Example 9-8: Bouncing Ball 9-62
Scrolling Backgrounds 9-68
Example 9-9: Horizontally Scrolling Background 9-71
Sprite Animation 9-76
Keyboard Events 9-79
Example 9-10. Sprite Animation 9-82
Collision Detection 9-87
Example 9-11: Collision Detection 9-88
Playing Sounds 9-93
Class Review 9-97
Practice Problems 9 9-98
Problem 9-1. Blackboard Problem
Problem 9-2. Rubber Band Problem
Problem 9-3. Shape Guessing Game
Problem 9-4. Plot Labels Problem
Problem 9-5. Bouncing Balls Problem
Problem 9-6. Moon Problem
Problem 9-7. Sound File Problem
Exercise 9: The Original Video Game - Pong! 9-99

10. Other Windows Application Topics

Review and Preview 10-1
Other Controls 10-2
LinkLabel Control 10-4
Example 10-1: Link Label Control 10-5
MonthCalendar Control 10-7
DateTimePicker Control 10-9
Example 10-2: Date Selections 10-10
RichTextbox Control 10-12
Example 10-3: Rich Text Box Example 10-15
ToolStrip (ToolBar) Control 10-18
Example 10-4: Note Editor Toolbar 10-22
ToolTip Control 10-28
Adding Controls at Run-Time 10-29
Example 10-5: Rolodex – Adding Controls at Run-Time 10-31
Printing with Visual C# 10-34
Printing Pages of a Document 10-37
PageSetupDialog Control 10-43
PrintDialog Control 10-46
PrintPreviewDialog Control 10-58
Example 10-6: Printing 10-50
Using the Windows API 10-59
Timing with the Windows API 10-61
Example 10-7: Stopwatch Application (Revisited) 10-63
Adding a Help System to Your Application 10-65
Creating a Help File 10-67
Starting HTML Help Workshop 10-68
Creating Topic Files 10-70
Creating Table of Contents File 10-73
Compiling the Help File 10-78
HelpProvider Control 10-81
Example 10-7: Help System Display 10-83
Class Review 10-85
Practice Problems 10 10-86
Problem 10-1. Biorhythm Problem
Problem 10-2. Rich Textbox Note Editor Problem
Problem 10-3. Loan Printing Problem
Problem 10-4. Plot Printing Problem
Problem 10-5. Sound Timing Problem
Problem 10-6. Note Editor Help Problem
Exercise 10: Phone Directory 10-88

11. Visual C# Database and Web Applications

Review and Preview 11-1
Database Applications 11-2
Database Structure and Terminology 11-3
DataSet Objects 11-7
Simple Data Binding 11-16
Database Navigation 11-18
Example 11-1: Accessing the Books Database 11-19
Creating a Virtual Table 11-26
Example 11-2: Creating a Virtual Table 11-27
DataView Objects 11-36
Example 11-3: ‘Rolodex’ Searching of the Books Database 11-39
Complex Data Binding 11-43
Web Applications 11-47
Starting a New Web Application 11-49
Web Form Controls 11-51
Building a Web Application 11-58
Example 11-4: Loan Payments 11-61
Example 11-5: Loan Repayment Schedule 11-67
Class Review 11-72
Course Summary 11-73
Practice Problems 11 11-74
Problem 11-1. New DataView Problem
Problem 11-2. Multiple Authors Problem
Problem 11-3. Stopwatch Problem
Exercise 11: The Ultimate Application 11-75

Practice Problems Solutions (Part 1: Classes 1 to 5) P1-1
Practice Problems Solutions (Part 2: Classes 6 to 10) P2-1

Exercise Solutions (Part 1: Classes 1 to 5) E1-1
Exercise Solutions (Part 2: Classes 6 to 10) E2-1