【发布时间】:2021-05-12 16:48:47
【问题描述】:
【问题讨论】:
-
@dr.null 你能把这个添加为答案吗..
标签: c# .net system.drawing
【问题讨论】:
标签: c# .net system.drawing
定义矩形
Rectangle(left,top,width,height)
Rectangle[] rectangles = new Rectangle[2]
{
new Rectangle(0,0,100,50),
new Rectangle(200,100,200,50),
};
List<Rectangle> rectangles = new List<Rectangle>();
Rectangle rect = new Rectangle();
rect.X = 5;
rect.Y = 10;
rect.Width = 100;
rect.Height = 50;
rectangles.Add(rect);
获取底部和右侧的高度和宽度
int left = 100;
int top = 50;
int right = 400;
int bottom = 250;
int width = right - left;
int heigth = bottom - top;
Rectangle rect = new Rectangle(left, top, width, heigth);
绘制矩形数组
private void DrawRectangle()
{
Rectangle[] rectangles = new Rectangle[]
{
new Rectangle(0,0,100,50),
new Rectangle(200,100,200,50),
new Rectangle(300,200,160,60)
};
foreach(var rect in rectangles)
{
System.Drawing.SolidBrush myBrush = new System.Drawing.SolidBrush(System.Drawing.Color.Blue);
System.Drawing.Graphics formGraphics;
formGraphics = this.CreateGraphics();
formGraphics.FillRectangle(myBrush, rect);
myBrush.Dispose();
formGraphics.Dispose();
}
}
【讨论】:
试试这个:
Rectangle.FromLTRB(left, right, top, bottom);
【讨论】: