Solved

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

Posted on 2014-07-23
5
291 Views
Last Modified: 2014-09-15
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
0
Comment
Question by:Hg Tr
5 Comments
 
LVL 1

Accepted Solution

by:
Sameer Rakshe earned 450 total points
ID: 40214107
Simply click on picturebox and handle this event

private void pictureBox1_Click(object sender, EventArgs e)
{
    MouseEventArgs me = (MouseEventArgs)e;
    Point coordinates = me.Location;
}

you will get point co-ordinates
0
 
LVL 33

Expert Comment

by:sarabande
ID: 40214473
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
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 40214941
See this SO thread for an approach to converting coordinates:
stackoverflow.com/questions/10473582/how-to-retrieve-zoom-factor-of-a-winforms-picturebox
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
One of Google's most recent algorithm changes affecting local searches is entitled "The Pigeon Update." This update has dramatically enhanced search inquires for the keyword "Yelp." Google searches with the word "Yelp" included will now yield Yelp a…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now