Where are the embedded resouces?

  • Thread starter Thread starter John J. Hughes II
  • Start date Start date
J

John J. Hughes II

I use several embedded resources but sometimes have trouble determining
their path. Currently I have one that will not work at all and was
wondering what I did wrong.

Name space is: MyApp
Sub directory: icons
Name: coin.ico

I am trying to load a icon file like this.

return new Bitmap(GetType(), "icons.coins.ico");

I have tired:

MyApp.icons.coins.ico
icons.coins.ico
coins.ico

but none of them work.

What am I doing wrong?

Coins.ico is set as embedded with the compiler.

Regards,
John
 
Hi John,

First of all, I would like to confirm my understanding of your issue. From
your description, I understand that you need to get an embedded resource
from the manifest. If there is any misunderstanding, please feel free to
let me know.

When getting a bitmap or icon from manifest, we have to use
Assembly.GetManifestResourceStream() method to put the resource into a
stream and then construct a Bitmap object. Also we have to add the
namespace of the project before folder name in the resource name. Here is
an example:

System.Reflection.Assembly myAssembly =
System.Reflection.Assembly.GetExecutingAssembly();
Stream myStream =
myAssembly.GetManifestResourceStream("MyApp.icons.coins.ico");
if(myStream != null)
return new Bitmap(myStream);
else
return null;

For more information, please check the following link:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcon/html/
vbtskEmbeddingImageResourcesInProject.asp

HTH.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 
Hello Kevin,

Thanks again for the help!

I did not think that was what I was asking but you method works so I won't
complain :)

Any clue way "return new Bitmap(GetType(), "MyApp.icons.coins.ico");" did
not work but your method did? The name was the same and is not the Bitmap
overload supposed to handle getting the resource? I have another
application which uses the above and it works fine.

You method also has the advantage of allowing my program to compensate for
an error where the other method just sort of did not work and did not show
it.

Regards,
John
 
Hi John,

According to the exception message, return new Bitmap(GetType(),
"icons.coins.ico"); seems to be searching for the resource in the current
type, for example, a form. However, the icon was added under a seperate
folder which does not belong to any data type. So it cannot be found and
the exception is thrown.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 
Kevin,

Thanks for the response. I put the icons in a separate folder in all my
project but normally in a sub folder of that folder whereas in this case it
was a sub folder of the root. That might be the problem.

Oh well it works now ;)

regards,
John
 
Hi John,

Thanks for sharing your experience with all the people here. If you have
any questions, please feel free to post them in the community.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 
Back
Top