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

How to use Resource files in VS 2005?

P: n/a
Tom
This may seem a little strange, but in all my years of developing Windows
Forms apps, I've never really used Resource files; however, I would like
to start doing so in order to store icons, pictures, and most importantly,
error message strings in resource files so I don't have to go searching for
them inside the code (if I want them changed).

I know VS 2005 makes it MUCH easier to use and create resource files, but
in my few times I have tried I ended up not doing things right. Therefore,
does anyone know of any articles, tutorials, etc on how to createm use, and
ACCESS resource files (and items in them) in VS 2005? I am sure it is not
hard but a tutorial or something would go a long way in helping out.

Thanks a bunch.

Tom
Aug 31 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Well, it depends on what you want to do with it. I wasn't able to find
many good tutorials, but here is kinda what we use.

Go to 'add new item' and choose resource file, name it
MyResources.resx. VS will generate some code for this, but there are
ways to load the resource manager by hand. You can 'show all files'
on the project, and then look at the code it generates for the .resx
file to see how some of this works.

To get at a resource : MyResources.MyResources.res_name (returns
string/icon/etc)
To get the manager : MyResources.MyResources.ResourceManager

Loading it dynamically is a little harder, but not too bad. You just
have to know what assembly it is in, mostly. I wrote a utility class
that sits in the same dll as the resources, so I get my manager by
calling :

Dim resMgr as New ResourceManager(
GetType(IconResources.IconResources).Name,
Assembly.GetExecutingAssembly
)
// you could also use GetType(...).Assembly there.

After that you can call GetObject/GetResource on it, wrap it up with
nice functions, etc. Do this is if you need to have someone specify
which resource manager to return by name, not type. Also, look in the
code for the resx to see another way of loading the manager

So far it works pretty well for me. I can not get access to this
resource file from another dll (in designer mode) but it works great
for all my dynamic stuff.

HTH

Tom wrote:
This may seem a little strange, but in all my years of developing Windows
Forms apps, I've never really used Resource files; however, I would like
to start doing so in order to store icons, pictures, and most importantly,
error message strings in resource files so I don't have to go searching for
them inside the code (if I want them changed).

I know VS 2005 makes it MUCH easier to use and create resource files, but
in my few times I have tried I ended up not doing things right. Therefore,
does anyone know of any articles, tutorials, etc on how to createm use, and
ACCESS resource files (and items in them) in VS 2005? I am sure it is not
hard but a tutorial or something would go a long way in helping out.

Thanks a bunch.

Tom
Aug 31 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.