views:

570

answers:

3

Hi, I need to change the cursor image. Whenever the mouse is over my form I need to load my own image from a local path. I am using version 1.1 of the .NET framwork.

Here is what I have tried:

Cursor = new Cursor(GetType(),  Application.StartupPath+ "\\windowfi.cur");

But this throws an exception:

Value cannot be null.
Parameter name: dataStream

+1  A: 

This should probably work:

Cursor.Current = new Cursor(GetType(), Application.StartupPath+ @"\windowfi.cur");

or

Cursor.Current  = new Cursor(GetType(), Application.StartupPath+ "\\windowfi.cur");

Note the use of @ string literal and the \ escape character above to be able to use the backslash character correctly in the path to the cursor's icon. As well as the Current property of the Cursor class.

jpoh
He also has an escape character in his example. Good point on the .Current reference though.
spoon16
Nah, he didn't in the unedited version. But that's besides the point :-)
jpoh
A: 

It looks like you're using the wrong overload for the cursor constructor. If you want to use a file path, use the constructor overload that just takes a string. You are using the overload that takes a type and a string. That overload gets an embedded resource.

JP Alioto
+1  A: 

Cursor class has a constructor that takes in cur file path as a parameter. Use that. Like this:

this.Cursor = new Cursor("<your_cur_file_path");
danish