您的位置:首页 > 其它

Click事件也能获取鼠标单击的坐标

2014-01-23 21:34 309 查看
按照MSDN的说明以及平时的习惯,我们要获取鼠标单击时的相对坐标,都会使用MouseClick等事件,今天,偶然发现,原来Click事件也可以。



/*
惊天地泣鬼神的考古业绩。
* 原来Cilck事件也能获取鼠标点击的当前坐标,
MSDN上说要用MouseClick事件,哈哈
* 原来Click事件也可以!!!
* 但是,如果通过键盘引发事件,而不是通过鼠标操作,即不能获取。
* 鼠标右键单击无效。
*/

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
this.button1.Click += (s, e) =>
{
try
{
MessageBox.Show("事件源类型:" +
s.GetType().ToString() + "\n" +
"事件参数类型:" +
e.GetType().ToString() + "\n" +
"鼠标点击时X坐标:" +
((MouseEventArgs)e).X.ToString() + "\n" +
"Y坐标:" +
((MouseEventArgs)e).Y.ToString());
}
catch
{
MessageBox.Show("你可能通过回车键触发事件,无法获取数据。");
}
};
}
}
}


http://kanwoerzi.iteye.com/blog/1303725
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: