By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,218 Members | 1,381 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,218 IT Pros & Developers. It's quick & easy.

embedding a cursor in an application

P: n/a
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.

--
rgds, Wilfried [MapPoint MVP]
http://www.mestdagh.biz
Jan 28 '07 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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().GetManifestResourc eStream("WindowsApplication2.NE.ico");
bmp = new Bitmap(s);
Cursor = new Cursor(bmp.GetHicon());

--
rgds, Wilfried [MapPoint MVP]
http://www.mestdagh.biz

Wilfried Mestdagh wrote:
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.
Jan 28 '07 #2

P: n/a
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


Jan 29 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.