C# 获取鼠标在屏幕上的位置

获取鼠标位置及鼠标单击了哪个按键。
private void GetMousePoint()
{
     Point ms = Control.MousePosition;
     this.label2.Text = string.Format("当前鼠标位置:{0}:{1}", ms.X, ms.Y);
     MouseButtons mb = Control.MouseButtons;

    //  获取鼠标动作(按下了 那个按键)
     if (mb == System.Windows.Forms.MouseButtons.Left) this.label1.Text = "Left";           
     if (mb == System.Windows.Forms.MouseButtons.Right) this.label1.Text = "Right";
     if (mb == System.Windows.Forms.MouseButtons.Middle) this.label1.Text = "Middle";

}

//更新鼠标位置等信息。
private void timer1_Tick(object sender, EventArgs e)
{
     GetMousePoint();
}



posted @ 2020-02-26 12:47  snsnet  阅读(...)  评论(...编辑  收藏