歡迎加群交流 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);