GraphicsPath类—可以判断某一点是否在某一个graph的内部

例如有一个Ellipse,名称叫做element,现在有一个点clickPoint,我们就可以用下面的方法判断这个点是否在Ellipse的内部:

GraphicsPath areaPath = new GraphicsPath();

areaPath.AddEllipse(0, 0, (float)element.Width, (float)element.Height);

// 注意把Ellipse的左上角当作(0,0)点。

areaPath.CloseFigure();

if(areaPath.IsVisible(new System.Drawing.PointF((float)clickPoint.X, (float)clickPoint.Y)))

{

// 在里面

}

else

{

// 不在里面

}

对于其他的graph,如Polygon,有相应的AddPolygon方法。

你可能感兴趣的:(graphics)