برای یافتن مختصات x و y ماوس در هر نقطه از صفحه نمایش میتوانید از کد زیر استفاده کنید.
1-یک پروژه ویندوز فرم در ویژوال استودیو ایجاد کنید.
2-درست پس از نام کلاس class Form1 کد زیر را اضافه کنید.
1 2 3 4 5 |
[DllImport("user32.dll")] static extern bool GetCursorPos(ref Point lpPoint); //This is a replacement for Cursor.Position in WinForms [System.Runtime.InteropServices.DllImport("user32.dll")] static extern bool SetCursorPos(int x, int y); |
نحوه فراخوانی تابع :
1 2 3 4 5 6 7 8 |
private void getMousePosition() { Point pt = new Point(); GetCursorPos(ref pt); textBox3.Text = pt.X.ToString(); textBox4.Text = pt.Y.ToString(); } |
منبع : وبسایت حسین پورآذر
http://www.kasin.ir