I just want to know how can i drag and drop a line which was created dynamically at runtime (mouse draw line) in c# . The dynamic line was placed over a panel.
1 Answers
I have used two ways in the past:
On MouseDown calculate the distance between the line and the mouse cursor. If it is within a couple of pixels start dragging. While the MouseButton is down respond to the MouseMove by translating the startpoint and the endpoint of the line over the same vector (current mouse position - start dragging mouse position)
On MouseDown test the color of the pixel under the mouse cursor to see if it is over the line. If so do the same dragging as above.
The tricky thing is that option 1 is hard when there are multiple lines that are close and you need to find out which line needs to be dragged
Option 2 is hard when the line is very thin.
Another way is to draw a thicker line on an invisible bitmap when a line is drawn and test the pixel on the invisible bitmap. That way you can give a bit more tolerance AND you could give each invisible line a color that is distinct so it is easier to identify what line has been clicked.
Does this make sense?