Ionică Bizău
Ionică Bizău

Reputation: 113517

Selecting all mouse cursor types (one by one)

I'm developing a WPF application in C# and I want to know if is there any way to test all mouse cursor types. For changing the type of cursor I do this:

Mouse.OverrideCursor = Cursors.Cross;

I built a timer like bellow:

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

Here is my problem:

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

How can I do this?

Upvotes: 1

Views: 221

Answers (1)

DmitryG
DmitryG

Reputation: 17848

Try the following:

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[] { });
}

Upvotes: 3

Related Questions