How can I find the cursor position by coordinates ( X, Y ) relative to the screen, without resorting to Windows.Forms ?
1 answer
WPF has a Mouse class that has a GetPosition method. You can use the PointToScreen method to get the cursor position relative to the screen .
private void MainWindow_OnMouseMove(object sender, MouseEventArgs e) { var windowPosition = Mouse.GetPosition(this); var screenPosition = this.PointToScreen(windowPosition); this.Title = string.Format("{0} --- {1}", windowPosition, screenPosition); } Or as another option - use PInvoke .
- @Aplnvent; I'm up to date on
Mouse.GetPosition();but how to get coordinates relative to the screen using this method? - Arthur Edgarov - @ArthurEdgarov The method of the method can be applied to the result of the method
PointToScreenmsdn.microsoft.com/en-us/library/… - ApInvent - @ApInvent: You would give a snippet of code so you don’t have to read comments. - VladD
- one@VladD You are right, added an example to the answer. - ApInvent
|