private void MyMouseDownEvent(object sender, MouseEventArgs e) { // Get the current mouse position when the mouse button is pressed Point point = e.Location; int x = point.X; int y = point.Y; // Do something with the mouse position // ... }
private void MyMouseMoveEvent(object sender, MouseEventArgs e) { // Get the current mouse position when the mouse moves Point point = e.Location; int x = point.X; int y = point.Y; // Display the mouse position labelPosition.Text = $"Mouse Position: ({x}, {y})"; }Both code examples use the System.Windows.Forms package/library.