Class Pen
Represents a solid-colored pen used for drawing outlines of shapes. Encapsulates stroke properties such as thickness, color, line joins, line caps, miter limit, and alignment.
public sealed class Pen
- Inheritance
-
Pen
- Inherited Members
Examples
// Create a 3-pixel red pen with round joins and caps.
var pen = new Pen(new Color32(255, 0, 0), 3)
{
LineJoin = LineJoin.Round,
LineCap = LineCap.Round
};
var canvas = new Canvas(image);
canvas.DrawRectangle(Rectangle.FromSize(10, 10, 200, 100), pen);
Remarks
A Pen defines how shape outlines are rendered on a Canvas. The Size property controls the stroke thickness, while LineJoin, LineCap, MiterLimit, and Alignment fine-tune how corners, endpoints, and stroke positioning behave.
Constructors
- Pen(Color32, double)
Initializes a new instance of the Pen class with the specified color and thickness.
Properties
- Alignment
Gets or sets how the stroke is positioned relative to the shape boundary. Defaults to Center.
- Color
Gets the color of the pen used to draw outlines.
- LineJoin
Gets or sets the style used to join consecutive line segments at corners. Defaults to Miter.
- MiterLimit
Gets or sets the miter limit ratio used when Miter is specified. This value defines the maximum allowed ratio of the miter length to half of the pen's thickness before the join is converted to a bevel. Defaults to 4.0.
- Size
Gets the thickness of the pen, expressed in device-independent units. Must be greater than zero.