2012-07-23 23 views
1

我正在C#中開發一個WPF應用程序,我想知道是否有任何方法來測試所有鼠標光標類型。 爲了改變光標的類型我這樣做:選擇所有鼠標光標類型(逐個)

Mouse.OverrideCursor = Cursors.Cross; 

我建立像波紋管的計時器:

DispatcherTimer dt = new DispatcherTimer(); 
dt.Interval = new TimeSpan(0, 0, 0, 0, 300); 
dt.Tick += new EventHandler(dt_Tick); 
dt.Start(); 

這裏是我的問題:

Cursor c = Cursors.AppStarting; 
void dt_Tick(object sender, EventArgs e) 
{ 
    Mouse.OverrideCursor = c++; //this doesn't work. 
} 

我怎樣才能做到這一點?

回答

3

嘗試以下操作:

int current = 0; 
PropertyInfo[] cursors; 
void dt_Tick(object sender, EventArgs e) { 
    if(cursors == null) 
     cursors = typeof(Cursors).GetProperties(); 
    Mouse.OverrideCursor = 
     (Cursor)cursors[(current++) % cursors.Length].GetValue(null, 
                   new object[] { }); 
}