BlakeMcKenna
asked on
Pulling information from the "Resource" file within a Project?
I have added a "Resources" file to my project and have inserted Icon images for my ToolStrip control. Problem is that I need to retrieve the images and assign them to each ToolStripButton. Any ideas on how to do this?
Thanks!
Thanks!
http://visualbasic.about.com/od/usingvbnet/a/netres090117.htm
Right click on the button.
Select Set Image...
Activate Project resource file.
Select the image you want and OK.
Note that you can also add new image through that interface, so usually, the easiest way to go when you add a new button is to go straight there and Import.
Select Set Image...
Activate Project resource file.
Select the image you want and OK.
Note that you can also add new image through that interface, so usually, the easiest way to go when you add a new button is to go straight there and Import.
ASKER
James,
I've noticed by doing it your way when I go into the Resource file via the Project properties tab and selecting the Resource tab, the icon files don't show up even when I select Icons thru the filter.
I've noticed by doing it your way when I go into the Resource file via the Project properties tab and selecting the Resource tab, the icon files don't show up even when I select Icons thru the filter.
There are many resource files in an application.
The main one, is the one that you see in the project's Properties tab. But every form also has a resource file. At compile time, all the .resx files in the project are merged and incorporated in the assembly as one big resource store.
Including an image in the form's resource file is usually the preferred method if you know that an image will be used only in that form. If for some reason you eventually decide to remove that form from the project, its resources will go with it. You will thus not end up with resources that contain images that are no longer used.
If you think that you will be using the same image in different locations in the application, then it is better to add it to the main resources in the project's properties.
Using my method, you decide where you want the image to be saved as a resource by selecting either Local resource (the image is stored in the form's resources file) or Project resource file (the image is stored in the project's resources file).
The main one, is the one that you see in the project's Properties tab. But every form also has a resource file. At compile time, all the .resx files in the project are merged and incorporated in the assembly as one big resource store.
Including an image in the form's resource file is usually the preferred method if you know that an image will be used only in that form. If for some reason you eventually decide to remove that form from the project, its resources will go with it. You will thus not end up with resources that contain images that are no longer used.
If you think that you will be using the same image in different locations in the application, then it is better to add it to the main resources in the project's properties.
Using my method, you decide where you want the image to be saved as a resource by selecting either Local resource (the image is stored in the form's resources file) or Project resource file (the image is stored in the project's resources file).
ASKER
I think I'm going to abandon this approach and just add a directory "Images" to my project. With that said, how do I reference file from within that directory?
I would not go that way. Resources are the best way to distribute images. With a directory, you need to code everything, and do it with good error handling to prevent the application from crashing if the user "plays" with the directory. The user cannot delete or rename an image in the resources, but he can (and thus will :-) do it in a directory.
If you absolutely want to do it that way, then you need to load the images for each button with code like the following:
YourButton.Image = New Bitmap("<YourPath>.<YourIm age>")
This can slow down the loading of your form. Resources have been optimized to be fast.
If you absolutely want to do it that way, then you need to load the images for each button with code like the following:
YourButton.Image = New Bitmap("<YourPath>.<YourIm
This can slow down the loading of your form. Resources have been optimized to be fast.
ASKER
This is what I need to do for functionality purposes. My menu and toolbar menu is data driven. Each item is stored in a database (only once though). Each user will have specific permissions to a menu items and toolstrip items.
I need to retrieve the Icons (from where ever) associated with the Users permission level and create my ToolBar. The tag property of each menu/toolstrip item will contain a function_ID (a numeric value). Each Icon File is named like this: 1_Calibration.ico, 2_UserSetup.ico, 3_CustomSettings.ico, etc. I need to retrieve each file name, parse it out so I can retrieve the first digit to compare to the menu/toolstrip item tag property and then add the object to the menu and/or toolbar.
I need to retrieve the Icons (from where ever) associated with the Users permission level and create my ToolBar. The tag property of each menu/toolstrip item will contain a function_ID (a numeric value). Each Icon File is named like this: 1_Calibration.ico, 2_UserSetup.ico, 3_CustomSettings.ico, etc. I need to retrieve each file name, parse it out so I can retrieve the first digit to compare to the menu/toolstrip item tag property and then add the object to the menu and/or toolbar.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I've thought about that way as well and may end up doing that way just to keep it simple.
Thanks James!
Thanks James!
ASKER
This is the way I ended up going...Thanks James!