The code to do that can range from simple to not simple, depending on how you're drawing your lines.
Are the lines only horizontal or vertical? Are they all different colors? These are the kinds of things that can yield much easier solutions, and it's hard to tell what sort of a is-my-mouse-pointer-on-a-line algorithm to use without seeing the code that's drawing your lines.
Short version: Please post your code so we can see how you're drawing your lines.