Filling areas
Now that we have learned to draw simple shapes and change their appearance, we will learn to fill (paint) areas on the canvas. Two functions are designed for this, these are the methods FillRect (TRect* Rect) and FloodFill (x,y, Color, Style). Now we will analyze these methods in more detail.
Using the FillRect function, you can simply fill a specified rectangular area on the canvas. The type of fill is determined by the Brush property. The only parameter of this method is a simple TRect& Rect structure, which is just a set of 4 variables that define the boundaries of the area:
Let's consider a simple example of filling an area:
C++
Copied
void __fastcall TForm1::Button1Click(TObject *Sender)
{
TRect r; //Create a structure of type TRect
r.Left=0; //Set the left border of the area
r.right=600; //Set the right border
r.Bottom=600; //Set the bottom border
r.Top=0; //Set the top border of the area
Canvas->Brush->Color=clMoneyGreen; //Define the color of the fill
Canvas->FillRect(r); //Fill the specified area
}
//---------------------------------------------------------------------------
But you'll agree that there's too much code for such a simple action, so we can get rid of the first 5 lines like this:
C++
Copied
void __fastcall TForm1::Button1Click(TObject *Sender)
{
Canvas->Brush->Color=clMoneyGreen;
Canvas->FillRect(Rect(0,0,600,600));
}
//---------------------------------------------------------------------------
As you can see, the result will be the same.
I'm having a problem with the code:
C++
Copied
void __fastcal
Now that we have learned to draw simple shapes and change their appearance, we will learn to fill (paint) areas on the canvas. Two functions are designed for this, these are the methods FillRect (TRect* Rect) and FloodFill (x,y, Color, Style). Now we will analyze these methods in more detail.
Using the FillRect function, you can simply fill a specified rectangular area on the canvas. The type of fill is determined by the Brush property. The only parameter of this method is a simple TRect& Rect structure, which is just a set of 4 variables that define the boundaries of the area:
Let's consider a simple example of filling an area:
C++
Copied
void __fastcall TForm1::Button1Click(TObject *Sender)
{
TRect r; //Create a structure of type TRect
r.Left=0; //Set the left border of the area
r.right=600; //Set the right border
r.Bottom=600; //Set the bottom border
r.Top=0; //Set the top border of the area
Canvas->Brush->Color=clMoneyGreen; //Define the color of the fill
Canvas->FillRect(r); //Fill the specified area
}
//---------------------------------------------------------------------------
But you'll agree that there's too much code for such a simple action, so we can get rid of the first 5 lines like this:
C++
Copied
void __fastcall TForm1::Button1Click(TObject *Sender)
{
Canvas->Brush->Color=clMoneyGreen;
Canvas->FillRect(Rect(0,0,600,600));
}
//---------------------------------------------------------------------------
As you can see, the result will be the same.
I'm having a problem with the code:
C++
Copied
void __fastcal