Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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 :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

  1. Keep track of your lines in a data structure, e.g. an array, as you draw them.

  2. Create a handler for the panel’s MouseMove event.

  3. 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).

  4. If the distance is below a certain threshold, display the information.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading