简体   繁体   中英

How to set the background color of RectangleF c#?

如何设置使用rectangleF对象绘制的矩形的背景颜色。

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);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM