欢迎加群交流 QQ群 830426796
用 System.Drawing.Drawing2D.GraphicsPath 和 Region 类联合起来,然后用 Region.IsVisible(point) 函数,可以判断点是否在多边形区域内。
System.Drawing.Drawing2D.GraphicsPath myGraphicsPath=new System.Drawing.Drawing2D.GraphicsPath(); Region myRegion=new Region(); myGraphicsPath.Reset(); //添加构建多边形的点 Point p1=new Point(x1,y1); Point p2=new Point(x2,y2); Point p3=new Point(x3,y3); Point p4=new Point(x4,y4); myGraphicsPath.AddPolygon(LoadPoint(p1,p2,p2,p4)); myRegion.MakeEmpty(); myRegion.Union(myGraphicsPath); //返回判断点是否在多边形里 bool myPoint =myRegion.IsVisible(MousePoint);