«« 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);
var
  Region: HRGN;
  LogBrush: TLogBrush;
  NewBrush: hBrush;
begin
  with LogBrush do
  begin
    lbStyle := BS_HATCHED;
    lbColor := clBlue;
    lbHatch := HS_CROSS
  end;
  NewBrush := CreateBrushIndirect(LogBrush);
  Region := CreateEllipticRgnIndirect(PaintBox1.ClientRect);
  FillRgn(PaintBox1.Canvas.Handle, Region, NewBrush);
  DeleteObject(NewBrush);
  DeleteObject(Region)
end;

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 »