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
287 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
Comment Utility
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 32

Expert Comment

by:sarabande
Comment Utility
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
Comment Utility
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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Article by: Nadia
Suppose you use Uber application as a rider and you request a ride to go from one place to another. Your driver just arrived at the parking lot of your place. The only thing you know about the ride is the license plate number. How do you find your U…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

762 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

9 Experts available now in Live!

Get 1:1 Help Now