如何将鼠标坐标写入数组? [英] How to write the mouse coordinates to an array?

查看:80
本文介绍了如何将鼠标坐标写入数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好,这是我的项目,我有一个C#表单,并通过mouse_click事件获取鼠标坐标.我有一个图像框,我需要找到图像上按钮的坐标(它们是图像的一部分,而不是实际按钮).

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];



这是我要转换坐标的位置,例如第一次单击将给我array [0],它将是x1,y1,第二次单击将是array [1] = x2,y2,依此类推,在第四次之后将为零点击.

最终目标是稍后将这些坐标写入txt文件.

我的问题是好的,我知道它们将在一个数组中,但是我不知道如何将它们分配给一个数组.我是编程新手,将不胜感激.

谢谢



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

推荐答案

我建​​议您创建一个名为MouseCordinates的类,该类具有两个参数X和Y pos.
然后创建该类的列表.

当list.count> = 4时,停止输入并遍历list并简单地获取值.
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.


为什么在地球上将它们存储为文本?有一个Point类可以使用,在该类中数据仍然有用,如果您随时需要将其作为字符串,则可以使用ToString.
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.


这篇关于如何将鼠标坐标写入数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆