2016-11-19 44 views
-2

我想選擇的選擇按鈕被按下後鼠標從不僅從形式上整個屏幕座標。 請幫我這個。如何選擇使用C#Windows應用程序的鼠標座標?

using System; 
using System.Drawing; 
using System.Windows.Forms; 
using System.Runtime.InteropServices; 

namespace AutoClickker 
{ 
    public partial class Form1 : Form 
    { 
     int x = 0, y = 0; 

     public Form1() 
     { 
      InitializeComponent(); 
     } 

     private void btnSelectCoordinate_Click(object sender, MouseEventArgs e) 
     { 
      //base.OnMouseDoubleClick(); 
      // base.OnMouseEnter(e); 
      // base.OnMouseClick(e); 
      base.OnMouseMove(e); 
      x = e.X; 
      y = e.Y; 

      txtXCoordinate.Text = x.ToString(); 
      txtYCoordinate.Text = y.ToString(); 
     } 

    }  
} 

回答

1

只需使用系統光標位置財產Using Windows Cursor

using System.Windows.Forms 
    private void getCursorPosition() 
    { 
     int x = Cursor.Position.X; 
     int y = Cursor.Position.Y; 
    } 
+0

感謝您的幫助! 通過上述程序,我能夠選擇,我只跑了特定的座標形式,我需要從整個屏幕座標。 –

+0

是的,我的代碼做什麼,再次檢查。它可以讓你從整個屏幕 – Ogbe

+0

我檢查和運行協調,但是當它運行時採取默認的鼠標光標的位置,我需要像,如果你點擊屏幕上多次隨後也更新它的鼠標光標位置。 –

相關問題