添加引用: using System.Drawing.Drawing2D ; 界面上需要拉入控件:pictureBox 自己再琢磨一下吧
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);
{
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);
}
using System.Drawing.Drawing2D ;
界面上需要拉入控件:pictureBox
自己再琢磨一下吧
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);