Changing the Pen Color
Go Up to Using Pens
You can set the color of a pen as you would any other Color property at run time. 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:
procedure TForm1.PenColorClick(Sender: TObject);
begin
Canvas.Pen.Color := PenColor.ForegroundColor;
end;
void __fastcall TForm1::PenColorClick(TObject *Sender) {
Canvas->Pen->Color = PenColor->ForegroundColor;
}