WFC Pen Object

The capabilities of Win32 pens are encapsulated in the WFC Pen and PenStyle objects. The following code fragment demonstrates how to create a Pen object:

Pen p = new Pen(PenStyle.DASH);

The constant that you pass to the Pen object constructor is a pen style. The seven built-in pen styles supported on Windows are each represented by a constant defined in the PenStyle class. The PenStyle class is an enumeration class, which means that it defines a method (valid) that determines whether a value that you specify is a valid member of the PenStyle class.

The following table lists the PenStyle constants.

Constant Description
PenStyle.DASH Represents a dashed pen.
PenStyle.DOT Represents a dotted pen.
PenStyle.DASHDOT Represents a pen of alternating dashes and dots.
PenStyle.DASHDOTDOT Represents a pen of alternating dashes and double dots.
PenStyle.INSIDEFRAME Represents a pen that draws a line inside the frame of closed shapes produced by the Graphics object’s output functions that specify a bounding rectangle (for example, drawRect, drawPie, and drawChord).
PenStyle.NULL Represents a null pen.
PenStyle.SOLID Represents a solid pen.

In addition, the Pen object includes a group of public members that you can use to specify the kind of pen you want to create. Each of these members is a Pen object, and is designed to enable you to simulate various native features of the Windows user-interface.

For example, the Pen class defines a WINDOWFRAME member. When you create a Pen of type WINDOWFRAME, the lines that you draw using this pen look identical to the frame of an active window:

Pen pen = Pen.WINDOWFRAME;

The following table lists the Pen objects defined as public members of the Pen class.

Object Description
Pen.ACTIVECAPTIONTEXT Creates a pen the color of the active window's caption text.
Pen.CONTROLTEXT Represents a pen the color of the text on a control.
Pen.GRAYTEXT Represents a pen the color of disabled text.
Pen.HIGHLIGHTTEXT Represents a pen the color of highlighted text.
Pen.INACTIVECAPTIONTEXT Represents a pen the color of the caption text of an inactive window.
Pen.INFOTEXT Represents a pen the color of the information tooltip’s text.
Pen.MENUTEXT Represents a pen the color of menu text.
Pen.NULL Represents a null pen. A null pen does nothing.
Pen.WINDOWFRAME Represents a pen the color of an active window’s frame.
Pen.WINDOWTEXT Represents a pen the color of an active window’s text.

Note that when you use a Pen based on a system constant, such as the color of an active window’s text, a change in the system setting that the Pen reflects results in a change to the pen.