2011-09-13 40 views
-2

我想通過C#編程在系統的光標位置寫入一些數據。如何獲取光標位置並在C#.NET中寫入該位置?

我得到的光標位置爲Cursor.position,但無法寫入該位置。

+0

你想寫在光標所在位置的'control'嗎? –

+0

什麼是「一些數據」?你想寫什麼?你使用winforms或wpf或什麼? – mtijn

+0

我想他想以編程方式移動鼠標光標。在目前的狀態下,我們只能猜測他的意圖是什麼...... – MattDavey

回答

4

很難猜測這個問題的真實意圖。但這裏有一個簡單的WinForms形式的類,它什麼你問:

public partial class Form1 : Form { 
    public Form1() { 
     InitializeComponent(); 
     this.BackColor = this.TransparencyKey = Color.Fuchsia; 
     this.FormBorderStyle = FormBorderStyle.None; 
     var timer = new Timer() { Interval = 50, Enabled = true }; 
     timer.Tick += delegate { 
      this.Location = Cursor.Position; 
      // this.Invalidate(); // Uncomment if the text should change 
     }; 
    } 
    protected override void OnPaint(PaintEventArgs e) { 
     e.Graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.SingleBitPerPixelGridFit; 
     e.Graphics.DrawString("hello world", this.Font, Brushes.Black, 10, 0); 
    } 
} 

尋找一種方法來終止該程序是一個// TODO項目。