Chapter 31. Brushes, Pens, and Paths
After Graphics, Pen and Brush are the two most important graphics classes. Whenever you perform any drawing operation that does not manipulate an image's pixels directly, you use a Pen or a Brush.
Penclasses control the appearance of lines. They determine a line's color, thickness, dash style, and caps.Brushclasses control the appearance of filled areas. They can fill an area with solid colors, hatched colors, a tiled image, or different kinds of color gradients.
This chapter describes the Pen and Brush classes in detail. It shows how to use these classes to draw and fill all sorts of interesting shapes.
This chapter also describes the GraphicsPath class that represents a series of lines, shapes, curves, and text. You can fill a GraphicsPath using Pen and Brush classes.
You can download example programs demonstrating most of the methods described in this chapter on the book's web site. The examples also include code to draw the figures in this chapter.
Pen
The Pen object determines how lines are drawn. It determines the lines' color, thickness, dash style, join style, and end cap style.
A program can explicitly create Pen objects, but often it can simply use one of the more than 280 pens that are predefined by the Pens class. For example, the following code draws a rectangle using a hot pink line that's one pixel wide:
gr.DrawRectangle(Pens.HotPink, 10, 10, 50, 50)
Pen objects are scaled by transformations applied to a Graphics object, however, so the ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access