How to know if a GraphicsPath contains a point in C#

岁酱吖の 提交于 2019-12-01 03:47:45

I don't know a DrawingPath (you mean probably; graphics.DrawPath) but a GraphicsPath has the IsVisible method to check if a point is in the path.

bool isInPath = graphicsObj.IsVisible(point)

Using both .IsOutlineVisible and .IsVisible together cover the whole thing, border and within border, for this rectangle example, but as you know GraphicsPath can works for different shapes.

  bool b = gp.IsVisible(point) || gp.IsOutlineVisible(point, pen);     

For it in code

 Rectangle r = new Rectangle(new Point(50, 100), new Size(500, 100));
 bool b;
 // say Point p is set.
 // say Pen pen is set.

 using (var gp = new GraphicsPath())
 using (var pen = new Pen(Color.Black, 44)) {
    gp.AddRectangle(r);
    bool b = gp.IsVisible(point) || gp.IsOutlineVisible(point, pen);              
  }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!