Moving a drawn line with the mouse

后端 未结 2 538
南笙
南笙 2021-01-01 07:47

I am trying to move a drawn line by grabbing it with the mouse.

The line have already been drawn with Graphics.DrawLine(Pen P, Point A, Point B).

<
2条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-01 08:23

    I suggest you create a rectangle that is the width of the line and the length of the line, then you can use

    if(rectangle.Contains(Point p))
    {
       // do your move
    }
    

    You can also inflate the rectangle to make it easier to grab with:

    rectangle.Inflate(1, 1);
    

提交回复
热议问题