Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/282.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何绘制平行四边形集合线_C#_Collections_Drawrectangle - Fatal编程技术网

C# 如何绘制平行四边形集合线

C# 如何绘制平行四边形集合线,c#,collections,drawrectangle,C#,Collections,Drawrectangle,出于美观考虑,我想创建一条由平行四边形组成的直线,如下所示: 但事实证明,OnPaint override事件只允许您绘制矩形: protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); Rectangle[] rectangles = new Rectangle[] { new Rectangle(0, 0, 100, 30), new Rectang

出于美观考虑,我想创建一条由平行四边形组成的直线,如下所示:

但事实证明,OnPaint override事件只允许您绘制矩形:

protected override void OnPaint(PaintEventArgs e)
{
    base.OnPaint(e);

    Rectangle[] rectangles = new Rectangle[]
    {
         new Rectangle(0, 0, 100, 30),
         new Rectangle(100, 0, 100, 30),
         new Rectangle(200, 0, 100, 30),
         new Rectangle(300, 0, 100, 30),
         new Rectangle(400, 0, 100, 30),
    };

    e.Graphics.DrawRectangles(new Pen(Brushes.Black), rectangles);
}

我的问题是,我需要将矩形转换为平行四边形,并为每个矩形赋予不同的颜色。

填充多边形可以完成以下工作:

protected override void OnPaint(PaintEventArgs e) {
  base.OnPaint(e);
  e.Graphics.Clear(Color.White);

  int x = 10;
  int y = 10;
  int width = 148;
  int height = 64;
  int lean = 36;
  Color[] colors = new[] { Color.FromArgb(169, 198, 254),
                           Color.FromArgb(226, 112, 112),
                           Color.FromArgb(255, 226, 112),
                           Color.FromArgb(112, 226, 112),
                           Color.FromArgb(165, 142, 170)};

  e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
  for (int i = 0; i < colors.Length; ++i) {
    using (SolidBrush br = new SolidBrush(colors[i])) {
      e.Graphics.FillPolygon(br, new Point[] { new Point(x, y),
                                               new Point(x + lean, y + height),
                                               new Point(x + lean + width, y + height),
                                               new Point(x + width, y)});
      x += width;
    }
  }
}
protected override void OnPaint(PaintEventArgs e){
基础漆(e);
e、 图形。清晰(颜色。白色);
int x=10;
int y=10;
整数宽度=148;
整数高度=64;
int-lean=36;
Color[]colors=new[]{Color.FromArgb(169198254),
颜色。来自argb(226112112),
颜色。来自argb(255、226、112),
颜色。来自argb(112226112),
Color.FromArgb(165、142、170)};
e、 Graphics.SmoothingMode=SmoothingMode.AntiAlias;
对于(int i=0;i
/还有FillPolygon和DrawPolygon!