How to embed a existing cursor file into the application?
I was using Visual C# 2005 to build a GUI application. I needed to add existing cursor file into the project.
The procedure i followed was:
1) I added a existing cursor file into project.
2) Selected cursor file in the Solution Explorer > Chose View->Properties > Change the “Build Action” to “Embedded Resources”.
3) Code
Cursor newCur = new Cursor(“xyz.cur”);
this.Cursor = newCur;
But application was throwing exception “Could not find file C:\App\Debug\rotate.cur” even though i have added it in application.
After googling i found the solution at http://www.codeprof.com/dev-archive/37/9-31-373566.shtm
Here it goes:
1) Follow procedure 1 and 2 as done by me and Add
using System.Reflection;
using System.Resources;
using System.IO;
2) Actual code for getting resource (cursor)
Assembly asm = Assembly.GetExecutingAssembly();
using( Stream resStream = asm.GetManifestResourceStream( “MyNameSpace.xyz.cur” ) )
{
Cursor cursor = new Cursor( resStream );
}
where MyNamespace is name of our namespace.
3) Use
Form.Cursor = cursor;
The link also give the detailss of how to print all our resource names to the console (for example to lookup if the resource exists):
Assembly asm = Assembly.GetExecutingAssembly();
Console.WriteLine( “Manifest resources for {0}”, asm.FullName );
foreach( String resourceName in asm.GetManifestResourceNames() )
{
Console.WriteLine( “\t{0}”, resourceName );
}
uhm… what do you mean in PROJECT??? where can i find that PROJECT??? please help me…. thanks!!
Your Project in Solution Explorer.
Right click on your Project and click “Add New Item”.
Add the cursor file.