Resource file

G

Guest

Hi,
I have created a solution with two projects in it - a class library and a
windows forms front end. I have added a resource file (Resources.resx) to the
class library and filled it with icons.
Does anybody know how would I go about using an icon from this resource file
in the windows forms project?
Thanks in advance,
Al.
 
S

Stoitcho Goutsev \(100\)

Al,

You can use the Icon's constructor overload that accept a Type and a
resource name. The type needs to be declared in the assembly where the
resource is. The constructor uses the type for 2 pieces of information:
assembly and namespace, so the type and the resource needs to be under the
same namespace in the same assembly.

Other possiblility is to use Assembly.GetManifestResourceStream to get a
stream with the resource data and load it from there. This is BTW what
internaly the Icon constructor uses.

From experience I can tell that the tricky part is to get the resource
namespace right. VS IDE for C# puts all the resources under the default
namespace (property of the project) and then it appends the names of any
subfolder that the file might be in. VB's IDE works differently. If you have
problems loading the resource I'd suggest to use the reflector tool to check
out what is the correct namespace of the resource.
 
G

Guest

Hi Stoitcho,
Thanks for your help. It is the namespace that I am struggling with. I have
followed your advice and downloaded Reflector from the web but I'm struggling
to see how I can use this to return the basename of my resource file in
ProjectA to construct my resource manager in ProjectB. I have tried just
using the namespace of ProjectA but it tells me 'Could not find any resources
appropriate for the specified culture or the neutral culture'.
Any further help would be great,
Al.
 

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