问题
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:
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");
回答2:
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.
回答3:
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.
来源:https://stackoverflow.com/questions/1175870/how-can-i-change-the-mouse-cursor-image