如题,两个不规则多边形之间的区域(小多边形在大多边形内),需要填充颜色,如何使用GDI+做到?

解决方案 »

  1.   

    private void button3_Click(object sender, System.EventArgs e)
            {
                Graphics gp=this.pictureBox1.CreateGraphics();
                Rectangle rect1=new Rectangle(5,5,105,105);
                Rectangle rect2=new Rectangle(35,35,45,45);            gp.DrawRectangle(new Pen(Color.Green),rect1);
                gp.DrawRectangle(new Pen(Color.Red),rect2);            GraphicsPath path=new GraphicsPath();
                path.AddRectangle(rect1);
                path.AddRectangle(rect2);
                //Region rg=new Region(path);
                SolidBrush sbrush=new SolidBrush(Color.Blue);
                gp.FillPath(sbrush,path); 
                
            }
      

  2.   

    添加引用:
    using System.Drawing.Drawing2D ;
    界面上需要拉入控件:pictureBox
    自己再琢磨一下吧
      

  3.   

    GraphicsPath path = new GraphicsPath();
                Point[] p = new Point[] { new Point(2, 2), new Point(2, 100), new Point(100, 100), new Point(100, 2), new Point(2, 2) }; //大多边形
                Point[] b = new Point[] { new Point(20, 20), new Point(80, 20), new Point(80, 80), new Point(20, 70), new Point(20, 20) }; //小多边形            path.AddLines(p);
                path.AddLines(b);
                Graphics g = this.CreateGraphics();
                g.FillPath(Brushes.Red, path);