O'Reilly logo

.NET Windows Forms in a Nutshell by Matthew Adams, Ian Griffiths

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Name

Pen

Synopsis

This class describes the kind of line that is drawn when using the Graphics.DrawXXX() members.

Pens are resource-based entities, and it is therefore important to manage their lifetime carefully, calling Dispose() when you are finished with them, to release the resource to the system.

You can construct a Pen from a Color, Brush, or (optionally) a Width. If you use a Color, the line will be a solid, uniform color. If you use a Brush, you can take advantage of specific properties to render the line with a gradient or image texture. If you do not specify a width, the default value of 1 is used.

The width of the Pen is measured in pixels and is modified by any transforms that apply during the rendering process. As a geometric line has no intrinsic width, you can also specify an Alignment property, which determines where the pixels are rendered relative to the geometric line (see System.Drawing.Drawing2D.PenAlignment for more information on this). The default is to center the pixels across this theoretical line.

You can choose how to render the beginning and end of the line by specifying the StartCap and EndCap properties. You can choose one of several different styles from the System.Drawing.Drawing2D.LineCap enumeration, including butt-ends, round-ends, and simple arrows. If the predefined styles are not suitable, you can specify a CustomStartCap or CustomEndCap with an instance of the System.Drawing.Drawing2D.CustomLineCap class. This allows you to render more complex ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required