天天看點

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);         

        }