RAD Studio VCL Reference
ContentsIndex
PreviousUpNext
TCanvas.FillRect Method

Fills the specified rectangle on the canvas using the current brush.

Pascal
procedure FillRect(const Rect: TRect);
C++
__fastcall FillRect(const TRect Rect);

Use FillRect to fill a rectangular region using the current brush. The region is filled including the top and left sides of the rectangle, but excluding the bottom and right edges.  

C++ Examples: 

 

/*
The following code loads a bitmap from a file and assigns it
to the Brush of the Canvas of Form1:
*/

#include <memory>       //for STL auto_ptr class

void __fastcall TForm1::Button1Click(TObject *Sender)
{
  std::auto_ptr<Graphics::TBitmap> BrushBmp(new Graphics::TBitmap);
  BrushBmp->LoadFromFile("../bm1.BMP");
  Form1->Canvas->Brush->Bitmap = BrushBmp.get();
  Form1->Canvas->FillRect(Rect(0,0,100,100));
  Form1->Canvas->Brush->Bitmap = NULL;
}

 

Delphi Examples: 

{
The following code loads a bitmap from a file and assigns it
to the Brush of the Canvas of Form1:
} 
var
  Bitmap: TBitmap;

procedure TForm1.Button1Click(Sender: TObject);
begin
  Bitmap := TBitmap.Create;
  try
    Bitmap.LoadFromFile('bm1.BMP');
    Form1.Canvas.Brush.Bitmap := Bitmap;
    Form1.Canvas.FillRect(Rect(0,0,100,100));
  finally
    Form1.Canvas.Brush.Bitmap := nil;
    Bitmap.Free;
  end;
end; 

 

Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
What do you think about this topic? Send feedback!