I need to implement hit-testing for my Windows Form Control. I have my custom class which inherits the Control
class and I draw, in the OnPaint
method, a polyline:
e.Graphics.DrawLines(myPen, myPoints);
Now, during the MouseDown
event I get the position of the mouse and I implement the hit-testing like follow:
using (var path = new GraphicsPath())
{
path.AddLines(myPoints);
return path.IsVisible(pt);
}
The problem is that if have, for example, the polyline in figure (which may seem like a polygon) the IsVisible
method returns true even if I click inside the region that represents this polygon:
I need a different behavior, the method have to return true only if I click over the line. How can I do?