How can I change the mouse cursor image?
Asked Answered
C

3

1

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

Campobello answered 24/7, 2009 at 5:33 Comment(3)
This is your 50th question, and you have been on SO for 5 month (way longer than me). Why don't you start looking at a little bit of text formatting for your questions and just generally take a few minutes to phrase and punctuate the question properly? Not only would this often make clearer what you want, it also shows some respect for the people you're asking to help you.Kadiyevka
If you are going through all that time to complain you should at least do him a favor and reformat the question so he has an idea of what you would like to see in the future :)Haematocele
@spoon16 I would have done that immediately if he was a newbie. But this guy has been here for a long time and knows better.Kadiyevka
S
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");
Shovelhead answered 24/7, 2009 at 6:4 Comment(0)
C
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.

Claman answered 24/7, 2009 at 5:58 Comment(2)
He also has an escape character in his example. Good point on the .Current reference though.Haematocele
Nah, he didn't in the unedited version. But that's besides the point :-)Claman
S
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");
Shovelhead answered 24/7, 2009 at 6:4 Comment(0)
H
0

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.

Hurst answered 24/7, 2009 at 6:3 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.