Click here to Skip to main content
15,902,032 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello Again, CodeProject
Another one, this time
I am trying to create a custom cursor for my forms application
i.e not using the default ones but .cur files,
I added myCur.cur to my project,
then I also set the Build Action to "Embedded Resource", Also tried to set it to "Resource"
Here's the code samples I tried :
C#
///TRY Number I
Cursor mycur = new Cursor(GetType(),"myCur.cur")
this.Cursor = mycur
///TRY Number 2
Cursor mycur = new Cursor(GetType(),Application.StartUpPath + @"\myCur.cur")
this.Cursor = mycur
///TRY Number 3
Cursor mycur = new Cursor(Application.StartUpPath + @"\myCur.cur")
this.Cursor = mycur
///TRY Number 4
Cursor mycur = new Cursor("myCur.cur")
this.Cursor = mycur

For Try Number I,2 I get the following error:
C#
NullReferenceException was Unhandled
Parameter Name : Stream

For try number 3,4
C#
Invalid Image Format

where as the cursor works completely fine on Windows
Any Help would be appreciated.............

~Sids123
Posted

Here is what to do:

Create an *.resx file. On the resource node added to your project, choose "Add existing file" and add existing valid cursor file. It will add the file to your project (look at its properties: they will be set correctly) and will add a reference to the file in the resource file. This way, your file won't be copied to output directory, but it will be embedded in the executable module.

Now, how to use it. Look at the auto-generated code placed in a C# file as a child note to your resource Solution Explorer node. Open this file in a editor. Look for the name of the static property identical or close to your cursor file name. Look at the declaration: you will see how to use it.

—SA
 
Share this answer
 
You need to handle all the exception and provide a valid icon file for the Cursor image.
Have a look at this article and this would also provide you with a sample code in zipped format

[^]

If you find this answer helpful please rate it accordingly.

Cheers,
Kushagra
 
Share this answer
 
Comments
sid2x 4-Aug-13 2:27am    
I want to use a .cur file not text......
Kushagra Tiwari 4-Aug-13 2:59am    
Did you read the solution properly? It is using .cur files only. Regarding attaching an image file you can easily attach any bitmap for showing any cursor image you need

Cheers,
Kushagra

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900