GDI画图,判断鼠标点击点在某一画好的多边形、矩形、图形里

Region.IsVisible方法

简单方便准确

private bool CheckPntInPoly(Point[] points, Point pnt)

        {

            if (points == null || points.Length == 0 || pnt == Point.Empty)

            {

                return false;

            }

 

            System.Drawing.Drawing2D.GraphicsPath myGraphicsPath=newSystem.Drawing.Drawing2D.GraphicsPath();               

            Region myRegion=new Region();                       

            myGraphicsPath.Reset();  

 

            myGraphicsPath.AddPolygon(points); 

            myRegion.MakeEmpty();  

            myRegion.Union(myGraphicsPath);  

            //返回判断点是否在多边形里

            return myRegion.IsVisible(pnt);         

        }

 

原文地址:https://www.cnblogs.com/jhlong/p/5433818.html