views:

53

answers:

1

Hi all

I have created a mouse event handler that gives me the screen coordinate (X,Y) on a right click of the mouse.

I did that because I want to get the text ( a letter) that is located at that position.

I know how to get the XY position on the screen but I can't figure out how to get the text or object at that position.

Need some help...

Thank you !

A: 

It depends on how the text got there. Is it stored in a Label or a TextBox? If so, you can inspect those objects to find the text. If not, then the text is just a bunch of pixels. Without some sort of character recognition (which can be unreliable), there's no way to do it.

If you're using Windows forms, you can use the Location property of the MouseEventArgs argument that gets passed into the MouseDown events of your controls.

EDIT:

Since the text is being drawn using Graphics.DrawString, there's no context to tell you what the text is after it's drawn unless you maintain it yourself. You could create objects that encapsulate the bounding rectangles and values of the text, and iterate through those during mouse events.

Andy West
Andy The letters have been added to the screen with the graphics.DrawString method..
Bernard Larouche
That's what I was thinking I would have to do.Thanks
Bernard Larouche