Mittels der Methode GetCursorPos aus der user32.dll kann windowsweit die Mausposition ermittelt werden.
Dieses Beispiel schreibt die aktuelle Mausposition in die Titelleiste der Form. Die Abfrage der Position übernimmt ein Timer.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | using System.Runtime.InteropServices; .... [DllImport("user32.dll")] static extern bool GetCursorPos(ref Point lpPoint); Point MousePoint = new Point(); public Form1() { InitializeComponent(); timer1.Start(); } private void timer1_Tick(object sender, EventArgs e) { GetCursorPos(ref MousePoint); Text = "X = " + MousePoint.X.ToString() + " " + "Y = " + MousePoint.Y.ToString(); } |