?
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
Medium Priority
?
310 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 1

Accepted Solution

by:
Sameer Rakshe earned 1800 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 35

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

Get MongoDB database support online, now!

At Percona’s web store you can order your MongoDB database support needs in minutes. No hassles, no fuss, just pick and click. Pay online with a credit card. Handle your MongoDB database support now!

Question has a verified solution.

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

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…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
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…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses

770 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