Winform 获取鼠标移动坐标, 鼠标位置
Visual Studio:Visual Studio 2017
新建Form窗体,在窗体上拖拽StatusStrip控件,在StatusStrip控件上新增Label控件
注册鼠标移动事件
public Form1() { InitializeComponent(); // 鼠标移动事件 this.MouseMove += new System.Windows.Forms.MouseEventHandler(this.Form1_MouseMove); }
鼠标移动事件代码
/// <summary> /// 鼠标移动事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Form1_MouseMove(object sender, MouseEventArgs e) { // e.X, X轴坐标 // e.Y, Y轴坐标 toolStripStatusLabel1.Text = "鼠标位置 (" + e.X.ToString() + "," + e.Y.ToString() + ")"; }