PictureBox
にあるbmpに、マウスで移動できるGraphic.DrawLine()
の行を描画したいとします。マウスがライン上にあるかどうかを確認する機能はありません。マウスがGraphic.FillPolygon()
を超えているかどうかを確認する方法はたくさんありましたが、どれもDrawLine()
については確認できませんでした。それをチェックする良い解決策はありますか?ラインオーバー時にマウスをキャプチャする(Graphic.DrawLine())
編集: だから提案で、私はそのような機能を作っ:
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;
}
それはポリゴンのための素晴らしい作品。しかし、私はまだその行にマウスイベントを得ることはできません。助言がありますか?
これは常に完全な水平線または垂直線ですか、それ以外の角度ですか? –
いいえ、unfortunatelly任意の角度にすることができます、それ以上です、私は誰かが頂点をキャッチしたときに角度を変更する関数を追加したいです – Blabla