Changing the Pen Width
Go Up to Using Pens
A pen's width determines the thickness, in pixels, of the lines it draws.
Note: When the thickness is greater than 1, Windows always draws solid lines, regardless of the value of the pen's Style property.
To change the pen width, assign a numeric value to the pen's Width property.
Suppose you have a scroll bar on the pen's toolbar to set width values for the pen. And suppose you want to update the label next to the scroll bar to provide feedback to the user. Using the scroll bar's position to determine the pen width, you update the pen width every time the position changes.
This is how to handle the scroll bar's OnChange event:
procedure TForm1.PenWidthChange(Sender: TObject);
begin
Canvas.Pen.Width := PenWidth.Position; { set the pen width directly }
PenSize.Caption := IntToStr(PenWidth.Position); { convert to string for caption }
end;
void __fastcall TForm1::PenWidthChange(TObject *Sender) {
Canvas->Pen->Width = PenWidth->Position; // set the pen width directly
PenSize->Caption = IntToStr(PenWidth->Position); // convert to string
}