How can I get the Mouse POsition on click?
-
Hello everyone, I would like to be able to get the position of the mouse once the user click the mouse. Can someone be kind enough to tell me how this can be done? Thank you very much and have a great day. Khoramdin
-
Try using Form's MouseClick method , private void GetPosition(object sender, MouseEventArgs e) { int x = e.X; int y = e.Y; MessageBox.Show(x.ToString()+","+y.ToString()); }
Hello KKun, Thanx for the help, mate. I did exactly what you suggested and it is almost working! What I mean by almost is that I only get the mouse location at one particular Panel in the Windows Applicatin rather than the entire Appliication's Window. Can you think of anything which can cause such a problem? Thank you for your help, mate/ Khoramdin
-
Hello KKun, Thanx for the help, mate. I did exactly what you suggested and it is almost working! What I mean by almost is that I only get the mouse location at one particular Panel in the Windows Applicatin rather than the entire Appliication's Window. Can you think of anything which can cause such a problem? Thank you for your help, mate/ Khoramdin
For your problem ,i estmate that you have written code under Panel's MouseClick method ,i mean that not entire Application's Click method ,try again and make a reference to the the following code fragment,Good Luck!
public Form1() { InitializeComponent(); } _protected override void OnMouseClick(MouseEventArgs e) { int x = e.X; int y = e.Y; MessageBox.Show(x.ToString()+","+y.ToString()); base.OnMouseClick(e); }_