简体   繁体   中英

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.

  1. Keep track of your lines in a data structure, eg 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM