Solved

Pulling information from the "Resource" file within a Project?

Posted on 2014-02-05
10
216 Views
Last Modified: 2014-02-20
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!
0
Comment
Question by:BlakeMcKenna
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
10 Comments
 
LVL 9

Expert Comment

by:rawinnlnx9
ID: 39835967
0
 
LVL 40
ID: 39836174
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.
0
 

Author Comment

by:BlakeMcKenna
ID: 39836669
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.
0
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
LVL 40
ID: 39837043
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).
0
 

Author Comment

by:BlakeMcKenna
ID: 39837086
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?
0
 
LVL 40
ID: 39837229
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>.<YourImage>")

This can slow down the loading of your form. Resources have been optimized to be fast.
0
 

Author Comment

by:BlakeMcKenna
ID: 39837299
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.
0
 
LVL 40

Accepted Solution

by:
Jacques Bourgeois (James Burger) earned 500 total points
ID: 39837339
What I usually do in applications in which features depend on user ID is to create a full menu/toolstrip with everything ready in it, using resources for the images.

After reading the permissions in the database, I simply make the controls that are not visible to the user invisible. This is usually a lot less work than having to build the thing from scratch every time that the application starts.
0
 

Author Comment

by:BlakeMcKenna
ID: 39837369
I've thought about that way as well and may end up doing that way just to keep it simple.

Thanks James!
0
 

Author Closing Comment

by:BlakeMcKenna
ID: 39875491
This is the way I ended up going...Thanks James!
0

Featured Post

Get HTML5 Certified

Want to be a web developer? You'll need to know HTML. Prepare for HTML5 certification by enrolling in July's Course of the Month! It's free for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

623 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question