embedding a cursor in an application

W

Wilfried Mestdagh

Hi,

I create a new cursor like this:

Bitmap bmp = new Bitmap(fileName);
panel1.Cursor = new Cursor(bmp.GetHicon());

But now I want to embed the image in the executable. I have already add
the *.ICO file to the project, but how to access it in code ?

I'm using VS2005 SP1.
 
W

Wilfried Mestdagh

Found it. This was not so evident to find, so I wants to share:

- Add existing item to project and select the icon file
- Select the file in solution explorer, click right: properties
- Set Build action to: Embedded resource

Then you can get it a runtime with folowing code fragment. The trick is
that the namespace must be included in the name, and the whole thing
seems case sensitive:

using System.IO;
using System.Reflection;

Stream s =
Assembly.GetExecutingAssembly().GetManifestResourceStream("WindowsApplication2.NE.ico");
bmp = new Bitmap(s);
Cursor = new Cursor(bmp.GetHicon());
 
D

D. Yates

Also realize that you can add the icon to the resource file and access it
like so:

Cursor myCursor = GetCursor(Resources.NameOfYourIconResourse);

private Cursor GetCursor(byte[] data)
{
using (MemoryStream s = new MemoryStream(data))
return new Cursor(s);
}


Dave
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

creating a custom cursor 1
Save bmp/jpg/png...to icon (16x16) - Problem.. 3
Changing the cursor 2
Custom Mouse Cursor 1
wpf animated cursor 0
GetHicon memory leak 3
Bitmap and Icons 2
Strange exception in GDI + 2

Top