'How to detect whether the Mouse Hovers above a drawn line in C#
I have a panel on a form. On this panel there are drawn a few lines. I would like to know how to detect when the Mouse is above one of the lines and get the details of the line.
Solution 1:[1]
Keep track of your lines in a data structure, e.g. an array, as you draw them.
Create a handler for the panel's MouseMove event.
In the handler, iterate over the (array of) lines and compute the distance from the mouse's position to the nearest point on the line (see this article for the math).
If the distance is below a certain threshold, display the information.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | John Wu |
