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
301 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 34

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 86

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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
When there is a disconnect between the intentions of their creator and the recipient, when algorithms go awry, they can have disastrous consequences.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

733 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