I want to draw a line in a bmp which is located in PictureBox
with a Graphic.DrawLine()
, which I can move by mouse. I can't find any function to check if the mouse is on the line or not. I found many methods to check if the mouse is over the Graphic.FillPolygon()
but none about DrawLine()
. Is any good solution to check it?
Edit: So by the suggestion I made such a function:
private bool IsPointInPolygon4(Point[] poly, Point p)
{
System.Drawing.Drawing2D.GraphicsPath test = new System.Drawing.Drawing2D.GraphicsPath();
if (poly.Length == 2) // it means there are 2 points, so it's line not the polygon
{
test.AddLine(poly[0], poly[1]);
if (test.IsVisible(p, g))
{
MessageBox.Show("You clicked on the line, congratulations", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information);
test.Dispose();
return true;
}
}
else
{
test.AddPolygon(poly);
if (test.IsVisible(p, g))
{
MessageBox.Show("You clicked on the polygon, congratulations", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information);
return true;
}
}
return false;
}
It Works great for the polygons. But I can't still get the mouse event on the line. Any suggestions?