RAD Studio |  |

Changing the Pen Width
See Also
Collapse All

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:

Copy Code

    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;

Copy Code

    void __fastcall TForm1::PenWidthChange(TObject *Sender)
    {
      Canvas->Pen->Width = PenWidth->Position;         // set the pen width directly
      PenSize->Caption = IntToStr(PenWidth->Position); // convert to string
    }

See Also

Changing the Pen Color

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!