How to: Create a Pen (Visual C#)

This example demonstrates how to create a Pen object.

Example

System.Drawing.Pen myPen;
myPen = new System.Drawing.Pen(System.Drawing.Color.Black);
myPen.Dispose();

Compiling the Code

This example requires:

  • A Windows Forms Application project.

The code must be within the scope of the Form class. The instance of the form is represented by this.

Robust Programming

You should always call Dispose on any objects that consume system resources, such as Brush and Graphics objects.

See Also

Concepts

Designing a User Interface in Visual C#

Other Resources

Drawing Text and Graphics

Visual C# Guided Tour