Fill custom area with color

Little Helper picture Little Helper · Nov 27, 2011 · Viewed 16.4k times · Source

How can I fill a selected area with color?

var Rect: TRect;
    Color: TColor;
begin
  //fill area with color
end;

Answer

David Heffernan picture David Heffernan · Nov 27, 2011

You have not stated what you mean by custom area and you talk about a "selected area". I don't know what you mean.

For a simple rectangle then you typically would fill the rectangle with TCanvas.FillRect.

Canvas.Brush.Style := bsSolid;
Canvas.Brush.Color := Color;
Canvas.FillRect(R);

where R is a TRect specifying the rectangle.

For a more complex region then you need to fall back on the Windows GDI function FillRgn. This function is not wrapped by TCanvas but you can simply call it passing TCanvas.Handle as the HDC.