RAD Studio |  |

Changing the Pen Color
See Also
Collapse All

You can set the color of a pen as you would any other Color property at runtime. A pen's color determines the color of the lines the pen draws, including lines drawn as the boundaries of shapes, as well as other lines and polylines. To change the pen color, assign a value to the Color property of the pen.

To let the user choose a new color for the pen, put a color grid on the pen's toolbar. A color grid can set both foreground and background colors. For a non-grid pen style, you must consider the background color, which is drawn in the gaps between line segments. Background color comes from the Brush color property.

Since the user chooses a new color by clicking the grid, this code changes the pen's color in response to the OnClick event:

Copy Code

    procedure TForm1.PenColorClick(Sender: TObject);
    begin
    Canvas.Pen.Color := PenColor.ForegroundColor;
    end;

Copy Code

    void __fastcall TForm1::PenColorClick(TObject *Sender)
    {
      Canvas->Pen->Color = PenColor->ForegroundColor;
    }

See Also

Changing the Pen Width

Changing the Pen Style

Changing the Pen Mode

Getting the Pen Position

Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
What do you think about this topic? Send feedback!