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();
}




免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM