Click here to Skip to main content
15,899,935 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
How to change the image for cursor.
when i use
panel1.Cursor = new Cursor(GetType(), "in.cur");


Its showing exception as "Object reference not set to an instance of an object".

when i use like this
panel1.Cursor = new Cursor("zoom-in.cur");


It showing exception as "Image format is not valid. The image file may be corrupted.Parameter name: stream".

How to use it.
Posted
Updated 8-Nov-11 23:25pm
v2

Take a look at this forum discussion, same issue is discussed and resolved.
http://www.rw-designer.com/forum/1237[^]
 
Share this answer
 
In the first case, the problem will occur if you do not have the cursor stored as a Resource - if it is held as a separate file in your project, then you will get the null reference.

In the second case, check your CUR file - it isn't in Windows Cursor format. Did you rename a JPG, BMP or GIF and hope for the best?
 
Share this answer
 
To solve this issue , place your cursor file in the debug folder of the project and pass the filename like this:

C#
panel1.Cursor = new Cursor("in.cur");

Or
Pass the full path of the cursor file:
C#
panel1.Cursor = new Cursor("D:\\MyCursor\\in.cur");
 
Share this answer
 
Comments
Rajesh Anuhya 9-Nov-11 5:37am    
See the OP's exceptions, what he is getting..
ssyuvaraja 9-Nov-11 5:48am    
Image format is not valid. The image file may be corrupted.
Parameter name: stream is coming. But the image is .cur format only also the file is in the debug folder.
Rajesh Anuhya 9-Nov-11 7:10am    
Cursor have 2 overloads 1.Stream 2.string(filename), OP using string overload i.e again converted to the stream, better to use the stream to pass the .cur file.

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