A pen's Style property allows you to set solid lines, dashed lines, dotted lines, and so on.
The task of setting the properties of pen is an ideal case for having different controls share same event handler to handle events. To determine which control actually got the event, you check the Sender parameter.
procedure TForm1.SetPenStyle(Sender: TObject); begin with Canvas.Pen do begin if Sender = SolidPen then Style := psSolid else if Sender = DashPen then Style := psDash else if Sender = DotPen then Style := psDot else if Sender = DashDotPen then Style := psDashDot else if Sender = DashDotDotPen then Style := psDashDotDot else if Sender = ClearPen then Style := psClear; end; end;
void __fastcall TForm1::SetPenStyle(TObject *Sender) { if (Sender == SolidPen) Canvas->Pen->Style = psSolid; else if (Sender == DashPen) Canvas->Pen->Style = psDash; else if (Sender == DotPen) Canvas->Pen->Style = psDot; else if (Sender == DashDotPen) Canvas->Pen->Style = psDashDot; else if (Sender == DashDotDotPen) Canvas->Pen->Style = psDashDotDot; ' else if (Sender == ClearPen) Canvas->Pen->Style = psClear; }
void __fastcall TForm1::SetPenStyle(TObject *Sender) { if (Sender->InheritsFrom (__classid(TSpeedButton)) Canvas->Pen->Style = (TPenStyle) ((TSpeedButton *)Sender)->Tag; }
Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
|
What do you think about this topic? Send feedback!
|