在一个Form里如何得到鼠标的位置想必很多人都知道,只是如何得到系统鼠标的位置也许会让一些人挠头。对于这种跟系统有关系的事情,我们往往要通过调用Win32的API来实现:

下面的代码是C#,只是示范,很不规范,请勿因此扔鸡蛋:

[DllImport("user32.dll")]
        public static extern bool GetCursorPos(out Point pt);

 

private void timer1_Tick(object sender, EventArgs e)
{
    Point CursorPosition;
    GetCursorPos(out CursorPosition);
    label1.Text = "X: " + CursorPosition.X.ToString() + " Y: " +  CursorPosition.Y.ToString();
}

 

附件是示范程序:OnMyWayC.rar

相关文章:

  • 2022-02-11
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-02-09
  • 2022-01-26
  • 2021-10-21
  • 2021-12-17
猜你喜欢
  • 2022-01-08
  • 2022-12-23
  • 2022-01-19
  • 2022-02-03
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案