Notice Of Closure

Please note that this website is due to close down on 15th June 2020.

In the interim I will try to move as much content as possible over to my GitHub account. Thanks to everyone who has supported the site over the years.

» Help

How to create a brush using CreateBrushIndirect


Drop a TPaintBox control and a TButton on a form and add the following code to the button's OnClick event handler.

Run the application and see a blue hatched ellipse drawn in the paint box.

procedure TForm1.Button1Click(Sender: TObject);
  Region: HRGN;
  LogBrush: TLogBrush;
  NewBrush: hBrush;
  with LogBrush do
    lbStyle := BS_HATCHED;
    lbColor := clBlue;
    lbHatch := HS_CROSS
  NewBrush := CreateBrushIndirect(LogBrush);
  Region := CreateEllipticRgnIndirect(PaintBox1.ClientRect);
  FillRgn(PaintBox1.Canvas.Handle, Region, NewBrush);

Tip modified and expanded by Peter Johnson.

Original resource: The Delphi Pool
Author: Earl F. Glynn
Added: 2009-09-14
Last updated: 2009-09-14

« Return to contents »