MSDN Community – GDI+ Documentation

Pen Class

The Pen class defines an object used to draw lines and curves. It encapsulates a Brush, width, dash style, line caps, and more.

Namespace

System.Drawing.Drawing2D

Inheritance

Object → Pen

Constructor Summary

SignatureDescription
Pen(Color color)Creates a new pen with the specified color and a width of 1.0.
Pen(Color color, float width)Creates a new pen with the specified color and width.
Pen(Brush brush, float width)Creates a new pen that uses the specified brush and width.

Properties

NameTypeDescription
ColorColorGets or sets the color of the pen.
WidthfloatGets or sets the width of the pen.
DashStyleDashStyleSpecifies the dash pattern.
StartCapLineCapDefines the shape of the line's start cap.
EndCapLineCapDefines the shape of the line's end cap.
LineJoinLineJoinSpecifies the type of join for two lines.
MiterLimitfloatLimits the length of the miter.

Methods

SignatureDescription
Clone()Creates an exact copy of the Pen.
Dispose()Releases all resources used by the Pen.
ResetTransform()Resets the transformation matrix to identity.
MultiplyTransform(Matrix matrix, MatrixOrder order = MatrixOrder.Prepend)Multiplies the current transformation matrix.

Example

// Draw a dashed red line using Pen
using System.Drawing;
using System.Drawing.Drawing2D;

public void DrawSample(Graphics g)
{
    using (Pen pen = new Pen(Color.Red, 3))
    {
        pen.DashStyle = DashStyle.Dash;
        pen.StartCap = LineCap.Round;
        pen.EndCap = LineCap.ArrowAnchor;
        g.DrawLine(pen, new Point(20, 20), new Point(200, 150));
    }
}

Related Classes