Using resource file

  • Thread starter Mats-Lennart Hansson
  • Start date
M

Mats-Lennart Hansson

Hi,
I want to create a resource file with 2 icons and then use them in a c#
project. First I create the resx file with reseditor.exe. After that I add
the resx-file into my project and then I try to get the icon by using the
code:

Assembly a = Assembly.GetExecutingAssembly();
ResourceManager rm = new ResourceManager("Resource1", a);

Icon i = (Icon) rm.GetObject("Running");

However, this does not work. I get an error saying something about a
manifest and that I must make sure that all files were added correctly.

Can anyone give me a step by step explanation on how I should do it?

Thanks,

Mats-Lennart
 
M

Mats-Lennart Hansson

Thanks, but your example uses an jpg and I want to use an icon (.ico). Is
there a similar way for icons as well?

Thanks,
Mats-Lennart

Nicholas Paldino said:
Mats-Lennart,

For culture-neutral items, I generally don't use the Resource manager
(especially for pictures and whatnot). I just read the stream directly.

Attached is a sample app that shows you how to read the resource stream,
as well as how to include it in your project.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Mats-Lennart Hansson said:
Hi,
I want to create a resource file with 2 icons and then use them in a c#
project. First I create the resx file with reseditor.exe. After that I add
the resx-file into my project and then I try to get the icon by using the
code:

Assembly a = Assembly.GetExecutingAssembly();
ResourceManager rm = new ResourceManager("Resource1", a);

Icon i = (Icon) rm.GetObject("Running");

However, this does not work. I get an error saying something about a
manifest and that I must make sure that all files were added correctly.

Can anyone give me a step by step explanation on how I should do it?

Thanks,

Mats-Lennart
 

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

Top