Home Page Icon
Home Page
Table of Contents for
Chapter 39: Drawing with GDI+ (3/3)
Close
Chapter 39: Drawing with GDI+ (3/3)
by Rod Stephens
Stephens' C# Programming with Visual Studio® 2010 24-Hour Trainer
Stephens’ C# Programming with Visual Studio® 2010 24-Hour Trainer
Copyright
About the Author
Credits
Acknowledgments
Brief contents
Contents (1/3)
Contents (2/3)
Contents (3/3)
Introduction
Who This Book Is For
What This Book Covers (And What It Doesn’t)
The Wrox 24-Hour Trainer Approach
How This Book Is Structured
What You Need to Use This Book
Conventions
Source Code
Errata
p2p.wrox.com
Section I: The Visual Studio IDE and Controls
Chapter 1: Getting Started with the Visual Studio IDE (1/4)
Chapter 1: Getting Started with the Visual Studio IDE (2/4)
Chapter 1: Getting Started with the Visual Studio IDE (3/4)
Chapter 1: Getting Started with the Visual Studio IDE (4/4)
Installing C#
Configuring the IDE
Building Your First Program
Copying Projects
Exploring the IDE
Try It
Exercises
Chapter 2: Creating Controls (1/4)
Chapter 2: Creating Controls (2/4)
Chapter 2: Creating Controls (3/4)
Chapter 2: Creating Controls (4/4)
Understanding Controls
Creating Controls
Setting Control Properties
Arranging Controls
Try It
Exercises
Chapter 3: Making Controls Arrange Themselves (1/2)
Chapter 3: Making Controls Arrange Themselves (2/2)
Restricting Form Size
Using Anchor Properties
Using Dock Properties
Try It
Exercises
Chapter 4: Handling Events (1/2)
Chapter 4: Handling Events (2/2)
Making Event Handlers
Using Event Parameters
Removing Event Handlers
Adding and Removing Event Handlers in Code
Useful Events
Try It
Exercises
Chapter 5: Making Menus (1/2)
Chapter 5: Making Menus (2/2)
Creating Menus
Setting Menu Properties
Handling Menu Events
Creating Context Menus
Try It
Exercises
Chapter 6: Making Tool Strips and Status Strips (1/3)
Chapter 6: Making Tool Strips and Status Strips (2/3)
Chapter 6: Making Tool Strips and Status Strips (3/3)
Using Tool Strips
Using Tool Strip Containers
Using Status Strips
Try It
Exercises
Chapter 7: Using RichTextBoxes (1/2)
Chapter 7: Using RichTextBoxes (2/2)
Using RichTextBox Properties
Giving the User Control
Using RichTextBox Methods
Try It
Exercises
Chapter 8: Using Standard Dialogs (1/3)
Chapter 8: Using Standard Dialogs (2/3)
Chapter 8: Using Standard Dialogs (3/3)
Using Dialogs in General
Using Dialog Properties
Using File Filters
Try It
Exercises
Chapter 9: Creating and Displaying New Forms (1/3)
Chapter 9: Creating and Displaying New Forms (2/3)
Chapter 9: Creating and Displaying New Forms (3/3)
Adding New Forms
Understanding Classes and Instances
Displaying Forms
Controlling Remote Forms
Try It
Exercises
Chapter 10: Building Custom Dialogs (1/2)
Chapter 10: Building Custom Dialogs (2/2)
Making Custom Dialogs
Setting the Dialog Result
Using Custom Dialogs
Try It
Exercises
Section II: Variables and Calculations
Chapter 11: Using Variables and Performing Calculations (1/5)
Chapter 11: Using Variables and Performing Calculations (2/5)
Chapter 11: Using Variables and Performing Calculations (3/5)
Chapter 11: Using Variables and Performing Calculations (4/5)
Chapter 11: Using Variables and Performing Calculations (5/5)
What Are Variables?
Data Types
Declaring Variables
Literal Values
Type Conversions
Performing Calculations
Constants
Try It
Exercises
Chapter 12: Debugging Code (1/3)
Chapter 12: Debugging Code (2/3)
Chapter 12: Debugging Code (3/3)
Deferred Techniques
Debugging Then and Now
Setting Breakpoints
Reading Variables
Stepping Through Code
Using Watches
Using the Immediate Window
Try It
Exercises
Chapter 13: Understanding Scope (1/3)
Chapter 13: Understanding Scope (2/3)
Chapter 13: Understanding Scope (3/3)
Scope Within a Class
Accessibility
Restricting Scope and Accessibility
Try It
Exercises
Chapter 14: Working with Strings (1/3)
Chapter 14: Working with Strings (2/3)
Chapter 14: Working with Strings (3/3)
String Methods
Format and ToString
Try It
Exercises
Chapter 15: Working with Dates and Times (1/2)
Chapter 15: Working with Dates and Times (2/2)
Creating DateTime Variables
Local and Utc Time
DateTime Properties and Methods
Timespans
Try It
Exercises
Chapter 16: Using Arrays and Collections (1/3)
Chapter 16: Using Arrays and Collections (2/3)
Chapter 16: Using Arrays and Collections (3/3)
Arrays
Collection Classes
Try It
Exercises
Chapter 17: Using Enumerations and Structures (1/2)
Chapter 17: Using Enumerations and Structures (2/2)
Enumerations
Structures
Structures Versus Classes
Try It
Exercises
Section II: Program Statements
Chapter 18: Making Choices (1/2)
Chapter 18: Making Choices (2/2)
Decision Statements
If Statements
If-Else
Cascading If Statements
Nested If Statements
Switch Statements
Try It
Exercises
Chapter 19: Repeating Program Steps (1/3)
Chapter 19: Repeating Program Steps (2/3)
Chapter 19: Repeating Program Steps (3/3)
For Loops
Foreach Loops
While Loops
Do Loops
Break and Continue
Try It
Exercises
Chapter 20: Reusing Code with Methods (1/2)
Chapter 20: Reusing Code with Methods (2/2)
Method Advantages
Method Syntax
Parameters by Reference
Try It
Exercises
Chapter 21: Handling Errors (1/2)
Chapter 21: Handling Errors (2/2)
Errors and Exceptions
Try-Catch Blocks
Throwing Errors
Try It
Exercises
Chapter 22: Preventing Bugs (1/2)
Chapter 22: Preventing Bugs (2/2)
Input Assertions
Other Assertions
Try It
Exercises
Section IV: Classes
Chapter 23: Defining Classes (1/4)
Chapter 23: Defining Classes (2/4)
Chapter 23: Defining Classes (3/4)
Chapter 23: Defining Classes (4/4)
What is a Class?
Class Benefits
Making a Class
Try It
Methods
Events
Try It
Inheritance
Polymorphism
Try It
Exercises
Chapter 24: Initializing Objects (1/3)
Chapter 24: Initializing Objects (2/3)
Chapter 24: Initializing Objects (3/3)
Initializing Objects
Constructors
Destructors
Invoking Other Constructors
Try It
Exercises
Chapter 25: Fine-Tuning Classes (1/2)
Chapter 25: Fine-Tuning Classes (2/2)
Overloading Methods
Overriding Methods
Try It
Exercises
Chapter 26: Overloading Operators (1/2)
Chapter 26: Overloading Operators (2/2)
Overloadable Operators
Unary Operators
Binary Operators
Comparison Operators
Try It
Exercises
Chapter 27: Using Interfaces (1/3)
Chapter 27: Using Interfaces (2/3)
Chapter 27: Using Interfaces (3/3)
Interface Advantages
Implementing Interfaces
Defining Interfaces
Try It
Exercises
Chapter 28: Making Generic Classes (1/2)
Chapter 28: Making Generic Classes (2/2)
Defining Generic Classes
Using Generic Constraints
Making Generic Methods
Try It
Exercises
Section V: System Interactions
Chapter 29: Reading and Writing Files (1/2)
Chapter 29: Reading and Writing Files (2/2)
Understanding Streams
Writing Files
Reading Files
Try It
Exercises
Chapter 30: Using File System Classes (1/2)
Chapter 30: Using File System Classes (2/2)
The DriveInfo Class
The DirectoryInfo Class
The Directory Class
The FileInfo Class
The File Class
The Path Class
Try It
Exercises
Chapter 31: Printing (1/2)
Chapter 31: Printing (2/2)
Basic Printing
Try It
Exercises
Chapter 32: Using the Clipboard (1/2)
Chapter 32: Using the Clipboard (2/2)
Adding Data to the Clipboard
Getting Data from the Clipboard
Try It
Exercises
Chapter 33: Providing Drag and Drop (1/2)
Chapter 33: Providing Drag and Drop (2/2)
Understanding Drag and Drop Events
Starting a Drag
Catching a Drop
Try It
Exercises
Section VI: Specialized Topics
Chapter 34: Localizing Programs (1/2)
Chapter 34: Localizing Programs (2/2)
Understanding Localization
Building Localized Interfaces
Processing Locale-Specific Values
Try It
Exercises
Chapter 35: Programming Databases, Part 1 (1/2)
Chapter 35: Programming Databases, Part 1 (2/2)
Connecting to a Database
Displaying Records in a Grid
Displaying Records One Row at a Time
Try It
Exercises
Chapter 36: Programming Databases, Part 2 (1/2)
Chapter 36: Programming Databases, Part 2 (2/2)
Searching
Filtering
Sorting
Try It
Exercises
Chapter 37: LINQ to Objects (1/3)
Chapter 37: LINQ to Objects (2/3)
Chapter 37: LINQ to Objects (3/3)
LINQ Basics
Where Clauses
Order By Clauses
Select Clauses
Try It
Exercises
Chapter 38: LINQ to SQL (1/3)
Chapter 38: LINQ to SQL (2/3)
Chapter 38: LINQ to SQL (3/3)
Connecting to the Database
Making LINQ to SQL Classes
Writing Code
Using LINQ Queries
Understanding Nullable Fields
Understanding Query Execution
Using LINQ to SQL with Access
Try It
Exercises
Chapter 39: Drawing with GDI+ (1/3)
Chapter 39: Drawing with GDI+ (2/3)
Chapter 39: Drawing with GDI+ (3/3)
Graphics
Pen
Brush
Try It
Exercises
Chapter 40: Making WPF Applications (1/3)
Chapter 40: Making WPF Applications (2/3)
Chapter 40: Making WPF Applications (3/3)
Weighing WPF’s Benefits and Weaknesses
Building WPF Applications
Arranging WPF Controls
Editing XAML Code
Using WPF Styles
Try It
Exercises
Chapter 41: Printing with WPF (1/2)
Chapter 41: Printing with WPF (2/2)
Printing Visuals
Try It
Exercises
Appendix A: Glossary (1/2)
Appendix A: Glossary (2/2)
Appendix B: Control Summary (1/2)
Appendix B: Control Summary (2/2)
Appendix C: What’s on the DVD?
System Requirements
Using the DVD
What’s on the DVD
Troubleshooting
Customer Care
Index (1/6)
Index (2/6)
Index (3/6)
Index (4/6)
Index (5/6)
Index (6/6)
Search in book...
Toggle Font Controls
Playlists
Add To
Create new playlist
Name your new playlist
Playlist description (optional)
Cancel
Create playlist
Sign In
Email address
Password
Forgot Password?
Create account
Login
or
Continue with Facebook
Continue with Google
Sign Up
Full Name
Email address
Confirm Email Address
Password
Login
Create account
or
Continue with Facebook
Continue with Google
Prev
Previous Chapter
Chapter 39: Drawing with GDI+ (2/3)
Next
Next Chapter
Chapter 40: Making WPF Applications (1/3)
Exercises
4
47
{
// Find the next point’s coordinates.
oat x1 = marginX + scaleX * i;
oat y1 = graphPictureBox.ClientSize.Height –
marginY - scaleY * values[i];
// Draw a line from the previous point to this one.
graphics.DrawLine(Pens.Black, x0, y0, x1, y1);
// Draw this point’s value in text.
if (values[i] >= 50)
{
graphics.DrawString(values[i].ToString(),
this.Font, Brushes.Black, x1, y1 - 12);
}
else
{
graphics.DrawString(values[i].ToString(),
this.Font, Brushes.Red, x1, y1);
}
// Update (x0, y0).
x0 = x1;
y0 = y1;
}
}
Ple
ase se
lec
t Le
sson 39 o
n the D
V
D t
o vie
w the vi
de
o that ac
com
pani
es thi
s le
sson
.
EXERCISES
1.
Build a program that uses a
Paint
event handler to draw a picture similar to the one shown
in Figure 39-6. (Feel free to embellish with ears, a hat, a scarf, or anything else you like.)
2.
Build a program that uses a
Paint
event handler to draw a bar chart similar to the one
shown in Figure 39-7. (Hint: Use the program you built for the Try It as a starting point.)
FI
GUR
E 39
6
FI
GUR
E 39
7
596906c39.indd 447
4/7/10 12:35:15 PM
448
LES
SON
39
D
raw
in
g wit
h gDi
+
Y
ou c
an do
wn
loa
d the solut
ion
s to thes
e exe
r
ci
ses f
rom the book’s web page at
www.wrox.com
or
www.CSharpHelper.com/24hour.html
. Y
o
u ca
n fin
d those
solu
tion
s in the L
es
son
39 folde
r
.
3.
Build a Scribble program similar to the one shown in Figure 39-8. Hints: Make fields
isDrawing
(true when drawing) and
lastPoint
(the last point drawn). Make a
MouseDown
event handler that sets
isDrawing
to
true
and records the current point. In the
MouseMove
event handler, verify that the user is drawing, draw between the last and current points, and
update
lastPoint
. In the
MouseUp
event handler, set
isDrawing
to false. Do all drawing on
a
Bitmap
that is created when the program starts and if the user selects the File menu’s New
command. Finally, be sure to call the
PictureBox
’s
Refresh
method any time you draw.
4.
(Hard) Make a program that uses a
Paint
event handler to draw a star as shown in
Figure 39-9. Make the number of points a constant and allocate arrays big enough to hold
the star’s corner points and the
PathGradientBrush
’s
SurroundColors
. (Hint: If the star
has 7 points as in Figure 39-9, you’ll need 14 corner points in the polygon and 14 colors for
the brush.) Use
Math.Cos
and
Math.Sin
to calculate positions for the points.
FI
GUR
E 39
8
FI
GUR
E 39
9
596906c39.indd 448
4/7/10 12:35:15 PM
Click here to Play
Add Highlight
No Comment
..................Content has been hidden....................
You can't read the all page of ebook, please click
here
login for view all page.
Day Mode
Cloud Mode
Night Mode
Reset