Click here to Skip to main content
15,891,976 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Ok here is my project, I have a form in C# and getting mouse coordinates with mouse_click event. I have a image box and I need to find the coordinates of the buttons on the image (they are part of the image not actual buttons).

Point p2 = PointToClient(Cursor.Position);
string coords = string.Format("({0},{1})", p2.X, p2.Y);
Clipboard.SetText(coords);


This is how I am getting the coordinates, then I created an string array

string[] imgcoor = new string[4];


This is where I want to fwd the coordinates, like first click will give me array[0] which will be x1,y1, second click will be array[1] = x2,y2 and so on and it will be zero after the forth click.

The ultimate goal is to write those coordinates to a txt file later on.

My problem is ok I know they will be in an array but i don't know how to assign them to one. I am new to programming and will appreciate the help and the explanation.

Thank you
Posted
Updated 20-May-10 7:53am
v2

Instead of array i would suggest you to create a class named MouseCordinates with two parameters X and Y pos.
Then create a list of that class.

when the list.count >= 4 then stop taking inputs and iterate over list and simply get the values.
 
Share this answer
 
Comments
TolgaCiftci 20-May-10 13:54pm    
I only need this once it won't be repetitive after i got the coordinates, I thought i can count coordinates and do imgcoor.count = 0 but as i said I am just learning :)
Christian Graus 20-May-10 13:59pm    
Why create a class instead of storing as list of type Point ?
Jitendra Zaa 21-May-10 1:40am    
Ya Graus.. you are right. we can use class Point. :)
Why on earth would you store them as text ? There's a Point class you can use, where the data remains useful, it has a ToString if you need it as a string at any point.
 
Share this answer
 
Comments
TolgaCiftci 20-May-10 14:03pm    
I have a picture of a device which has 24 buttons. I need to get the coordinates to each button and save them and use the coordinates to test press and release functions coming from the device. I have more than one device and my idea is to get the coordinates of device buttons and save them like as1.txt for one device and as2.txt for the other. When application starts it will check the devicetxt folder and match the device name with the txt so when I use button press/release functions it will parse the coordinates from the txt file and display a check mark or paint it when the button on the device is pressed.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900