选择所有鼠标光标类型(逐个)

时间:2012-07-23 13:58:24

标签: c# wpf cursor

我正在用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. 
} 

我该怎么做?

1 个答案:

答案 0 :(得分: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[] { });
}
相关问题