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 ...

Get .NET Windows Forms in a Nutshell now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.