如何通过鼠标点击获取Windows窗体中的点数? [英] how to get points in windows form on mouse click?

查看:155
本文介绍了如何通过鼠标点击获取Windows窗体中的点数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


在我的应用程序中,我试图获取Windows窗体中的点,以便将这些点连接起来形成特定的形状。我经历了很多搜索我没有得到任何答案。

i是C#的新手#请帮助我如何获得鼠标点击活动积分





private void Form1_MouseClick(object sender,MouseEventArgs e)

{

}

In my application i am trying to get points in windows form in order join these points to form a specific shape. i gone through lot of search i did't get any answer.
i am new to C# please any one help me how to get points on mouse click event


private void Form1_MouseClick(object sender, MouseEventArgs e)
{
}

推荐答案

查看MouseEventArgs类,并且你会发现它有一个Location属性 - 告诉你鼠标在点击时的位置。

如果你创建了一个类级别的List或Point结构,那么你只需要添加新的位置到该列表供以后处理:

Look at the MouseEventArgs class, and you will find it has a Location property - which tells you where the mouse was when it was clicked.
If you create a class level List or Point structs, then you cna just add the new location to that list for later processing:
private List<Point> points = new List<Point>();
private void Form1_MouseClick(object sender, MouseEventArgs e)
    {
    points.Add(e.Location);
    }


你可以使用

you can use
private void Form1_MouseClick(object sender, MouseEventArgs e)
        {
            e.Location;
        }


这篇关于如何通过鼠标点击获取Windows窗体中的点数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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