RAD Studio
ContentsIndex
PreviousUpNext
Changing the Brush Style

A brush style determines what pattern the canvas uses to fill shapes. It lets you specify various ways to combine the brush’s color with any colors already on the canvas. The predefined styles include solid color, no color, and various line and hatch patterns. 

To change the style of a brush, set its Style property to one of the predefined values: bsBDiagonal, bsClear, bsCross, bsDiagCross, bsFDiagonal, bsHorizontal, bsSolid, or bsVertical. Cross-platform applications include the predefined values of bsDense1 through bsDense7. 

This example sets brush styles by sharing a click-event handler for a set of eight brush-style buttons. All eight buttons are selected, the Object InspectorEventsOnClick is set, and the OnClick handler is named SetBrushStyle. 

Here is the handler code:

procedure TForm1.SetBrushStyle(Sender: TObject);
begin
  with Canvas.Brush do
  begin
    if Sender = SolidBrush then Style := bsSolid
   else if Sender = ClearBrush then Style := bsClear
   else if Sender = HorizontalBrush then Style := bsHorizontal
   else if Sender = VerticalBrush then Style := bsVertical
   else if Sender = FDiagonalBrush then Style := bsFDiagonal
   else if Sender = BDiagonalBrush then Style := bsBDiagonal
   else if Sender = CrossBrush then Style := bsCross
   else if Sender = DiagCrossBrush then Style := bsDiagCross;
  end;
end;
void __fastcall TForm1::SetBrushStyle(TObject *Sender)
{
if (Sender == SolidBrush)
  Canvas->Brush->Style = bsSolid;
else if (Sender == ClearBrush)
  Canvas->Brush->Style = bsClear;
else if (Sender == HorizontalBrush)
  Canvas->Brush->Style = bsHorizontal;
else if (Sender == VerticalBrush)
  Canvas->Brush->Style = bsVertical;
else if (Sender == FDiagonalBrush)
  Canvas->Brush->Style = bsFDiagonal;
else if (Sender == BDiagonalBrush)
  Canvas->Brush->Style = bsBDiagonal;
else if (Sender == CrossBrush)
  Canvas->Brush->Style = bsCross;
else if (Sender == DiagCrossBrush)
  Canvas->Brush->Style = bsDiagCross;
}

 

void __fastcall TForm1::SetBrushStyle(TObject *Sender)
{
   if (Sender->InheritsFrom (__classid(TSpeedButton))
    Canvas->Brush->Style = (TBrushStyle) ((TSpeedButton *)Sender)->Tag;
}
Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
What do you think about this topic? Send feedback!