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:
*/
void __fastcall TForm1::Button1Click(TObject *Sender)
{
  Graphics::TBitmap *BrushBmp = new Graphics::TBitmap;
  try
  {
    BrushBmp->LoadFromFile("../bm1.BMP");
    Form1->Canvas->Brush->Bitmap = BrushBmp;
    Form1->Canvas->FillRect(Rect(0,0,100,100));
  }
  __finally
  {
    Form1->Canvas->Brush->Bitmap = NULL;
    delete BrushBmp;
  }
}

 

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) 2008 CodeGear(TM). All Rights Reserved.
What do you think about this topic? Send feedback!