Pen Class

Represents a pen for drawing operations.

See the online help for image examples.

Definition

Namespace: KGySoft.Drawing.Shapes
Assembly: KGySoft.Drawing.Core (in KGySoft.Drawing.Core.dll) Version: 10.0.0-rc.1
C#
public sealed class Pen
Inheritance
Object    Pen

Remarks

Pens are used to draw the outline of shapes, or to draw primitive lines and curves.

A Pen instance is defined by a Brush (possibly implicitly by a single color) that determines the color or texture of the pen, and a Width that determines the width of the pen. The LineJoin, MiterLimit, StartCap, and EndCap properties determine how the ends and joins of lines are drawn.

Examples

The following table illustrates the behavior of some properties of the Pen class:

DescriptionImage Example
LineJoin: Specifies how to join the consecutive line segments. Can be Miter, Bevel or Round. The example images demonstrate these join types from the top to the bottom. All examples use a 10 pixel wide pen.Polygon drawn with JoinStyle = LineJoinStyle.Miter
Polygon drawn with JoinStyle = LineJoinStyle.Bevel
Polygon drawn with JoinStyle = LineJoinStyle.Round
StartCap and EndCap: Specify the style of the start and end points of an open figure. Can be Flat, Square, Round or Triangle. The example images demonstrate these cap types from the top to the bottom, using the same cap style at both ends. Please note that the only difference between Flat and Square styles is that the Flat style has the originally specified length, whereas the Square style extends the line by half of the pen width. All examples use a 10 pixel wide pen.10 pixel width line drawn with cap style Flat
10 pixel width line drawn with cap style Square
10 pixel width line drawn with cap style Round
10 pixel width line drawn with cap style Triangle
Brush: It allows setting a Brush explicitly, so the Pen can use not only a solid color but also a texture or any other brush. The example demonstrates a 10 pixel wide pen with a diagonal linear gradient brush using mirrored wrapping mode.Pen with a linear gradient brush

Constructors

Pen Initializes a new instance of the Pen class with a black color and a width of 1.
Pen(Brush, Single) Initializes a new instance of the Pen class with the specified brush and width.
Pen(Color32, Single) Initializes a new instance of the Pen class with the specified color and width.

Properties

Brush Gets or sets the Brush that determines the color or texture of the Pen.
Default value: The Brush instance that was either passed to the corresponding constructor, or was created implicitly from a color by the other constructors.
See the Examples section of the Pen class for image examples.
EndCap Gets or sets the LineCapStyle that specifies the style of the end point of an open figure. Makes a difference only if the Width is greater than 1.
Default value: Flat.
See the Examples section of the Pen class for image examples.
LineJoin Gets or sets the LineJoinStyle that specifies how to join the consecutive line segments.
Default value: Miter.
See the Examples section of the Pen class for image examples.
MiterLimit If the LineJoin is Miter, then gets or sets the limit for the ratio of the miter length to half the Width that determines whether the join is beveled or mitered. Makes a difference only if the Width is greater than 1.
Default value: 10.
StartCap Gets or sets the LineCapStyle that specifies the style of the start point of an open figure. Makes a difference only if the Width is greater than 1.
Default value: Flat.
See the Examples section of the Pen class for image examples.
Width Gets or sets the width of the Pen.
Default value: the width that was passed to the constructor, or 1, if it was not specified.

See Also