«« Site Rescued »»

While the site is still going to move from its current host, a new site will now take its place. More Info.

The new site may have less content, but the core will now remain. And it will now play nicely with phones! Keep an eye on the DelphiDabbler Blog for news.

» 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 »