Link to home
Start Free TrialLog in
Avatar of Hg Tr
Hg Tr

asked on

How to determine the coordinates of a point on a photo/image displayed in a win-form picture-box at run time?

Hello bros and sis, I've done a bit C# win-form programming but totally am a newbie when it comes to win-form graphics. I am supposed to draw some rectangles acting as photo frames on this graphic image of a family tree. That's done with no problem - but the arrangement is fine only if my family tree is displayed at a fixed size << which allows me to determine the x-, y- coordinates of point A, B, C at design time (Please see TreeBefore Attachment) - These overlay rectangles will do something when I click on them per project requirement.

Picture 1: Family Tree PictureBox - TreeBefore

Now my family tree picture-box is docked (dock-style is set to "fill") and the Size-mode of the picture-box is set to "zoom" so that the family tree can be automatically re-sized  when expanding or contracting the form, also per requirement. So far so good, no coding involved because I come across picturebox's client rectangle computing but it is not in use here. However, the trade-off I guess is that when I run my program the family tree is no longer displayed at the real physical dimensions, one time the window form bigger, the other times it'd be smaller, thus all my drawn rectangles are out of place. (Please  see TreeAfter Attachment)

Picture 2: Family Tree PictureBox - TreeAfter

In both situations, picture 1 and 2, how can I determine the X, Y coordinates? Is this X, Y computing a good approach for re-sizing my rectangles in that they can be drawn proportionally to the size of the family tree? is there any alternatives?

I really need some help. Thank you.
TreeBefore.png
TreeAfter.png
ASKER CERTIFIED SOLUTION
Avatar of Sameer Rakshe
Sameer Rakshe

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of sarabande
you could get a bitmap from screen (search for 'c# screenshot' in the web) and evaluate the picture row by row by checking the colors. you could foster this analysis by adding some pixels with a special color into the tree image.

but it would be much simpler if you could create a picture with the "labels" already added before it is loaded to the picture box.

Sara
See this SO thread for an approach to converting coordinates:
stackoverflow.com/questions/10473582/how-to-retrieve-zoom-factor-of-a-winforms-picturebox