Home >Backend Development >C++ >How to Get the Current Mouse Position in C#?
Getting the Mouse Position in C# Applications
Knowing the current mouse coordinates is essential for many C# applications needing precise user interaction control. This guide shows you how.
Screen Coordinates
To get the mouse position relative to the entire screen, use this property:
<code class="language-csharp">System.Windows.Forms.Cursor.Position;</code>
Example:
<code class="language-csharp">int x = System.Windows.Forms.Cursor.Position.X; int y = System.Windows.Forms.Cursor.Position.Y;</code>
Important: This needs to happen before the form is created, as it depends on the system's current state.
Important Notes:
System.Windows.Forms.Control.Mouse*
events.The above is the detailed content of How to Get the Current Mouse Position in C#?. For more information, please follow other related articles on the PHP Chinese website!