Reputation: 10805
How to set the background color of a rectangle drawn using rectangleF object.
Upvotes: 1
Views: 1852
Reputation: 63337
RectangleF
is just a structure to store some info of a rectangle measured in float
. GDI+
uses this structure to draw, fill the colorful stuff into it. We have to use the Graphics
object to fill it. Here is the example code for you:
//Fill on a Bitmap
Graphics g = Graphics.FromImage(someBitmap);
g.FillRectangle(Brushes.Green, yourRectangleF);
In some Paint
event handler, we can get the Graphics
object via the passed-in argument e
, normally of type PaintEventArgs
, like this:
//Fill on a Form
private void Form1_Paint(object sender, PaintEventArgs e){
e.Graphics.FillRectangle(Brushes.Green, yourRectangleF);
}
Upvotes: 3