473,414 Members | 1,843 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

How do I access images in the resx file as if they are in an array?

DOSrelic
I have an assignment program that uses an array of images that are created from a supporting resource folder but I wish to incorporate them into the final exe file so how do I make an array from the Resources.resx file please?

Also, one of the images in the resx file is incorrect and should be removed. How can I remove that please? Every time I try anything with the Resources.resx file the Visual Studio 2008 IDE hates me!
Any knowledgeable advice would be greatly appreciated, thanks.

Thanks & Best Regards
[DOSrelic]
¨`•._.®._.•´¨
Nov 2 '09 #1

✓ answered by tlhintoq

That is just way messy and old-school.

The ResourceManager already knows all the resources let's just ask it.
Resources are kept on a per-culture basis. This is so you can make your program culture-specific. You can have resources if you deploy in English, a different set for Spanish and so on. We are simply going to get all the resources for English in this case.

Expand|Select|Wrap|Line Numbers
  1. System.Resources.ResourceSet temp = Properties.Resources.ResourceManager.GetResourceSet(new CultureInfo("en-US"), false,false);
  2. if (temp == null)
  3. {
  4.     // No resources specific to English
  5.     // Look for other resourses in the language of your application
  6. }
  7. foreach (System.Collections.DictionaryEntry set in temp)
  8. {
  9.     Console.WriteLine(string.Format("{0}: {1}", set.Key, set.Value));
  10. }
Try running this. It will show you the full list of resources and their types. From there you can sort a list, throw out ones that don't start with the word "card" for example etc.

13 4525
Plater
7,872 Expert 4TB
Are you using the resource management stuff that VS does or are you trying to directly edit the file?
Nov 2 '09 #2
Hi Plater, The resource management stuff that VS does but there does not seem to be the ability to remove an image. I currently load them from files into an array as I don't know how to use the VS way so the program requires it's own resource sub-folder, thanks.
Nov 2 '09 #3
Hi there I have just started with Csharp and wrote a messy but usable memory card game using a folder with all the images of the cards but I really want to be able to store them in the executable via the project resource file. I can load the resource file but do not know how to retrieve them to assign them to the newly created card class objects.
Instead of the line:
static Bitmap _back = new Bitmap(AmemoryGame .cardBackFileNames[0]);
what should I use please? I sort of figured that I would use ResXResourceReader resxReader = new ResXResourceReader(...)but then realised I didn't even know the name of the file!
Can anyone give me some guidance on how to access my resx resource file images please? Any knowledgeable help would be greatly cheers.
Dec 27 '09 #4
tlhintoq
3,525 Expert 2GB
You can reach your resource images by reference.

Expand|Select|Wrap|Line Numbers
  1. MyImage = MyProgramNamespace.Properties.Resources.G5_iMac;
Dec 27 '09 #5
@tlhintoq
Thank you tlhintoq, I can now access the resource images individually but is there a way to sort them and put them into an array? I currently have an array of file names so I can assign a unique image to every new card object in a loop:
Expand|Select|Wrap|Line Numbers
  1. _cards[index].FrontBm = new Bitmap(AmemoryGameGlobals.cardFrontFileNames[index++]);
Dec 27 '09 #6
tlhintoq
3,525 Expert 2GB
I see no reason why you couldn't get a list of the resources, sort it, then assign within a loop.
Dec 27 '09 #7
Neither do I tlhintoq but I'm afraid I wouldn't know how to go about doing that! Can you offer any sage advice on that score please? I mean I have a list of resource names but how do I transfer them to an array automatically? Properties.Resources.ResourceManager.....? Are they not already held in an array of some type and if so can I not set an array to that?
Dec 28 '09 #8
alexis4
113 100+
I could think that as a "stack pointer" type of solution. Have a counter variable starting from 0, increasing every time a picture gets in resource file and decreasing every time a picture gets out. In this way you can retrieve any element of the array at any time. Build that in an array structure or class and have all the information about your image inside this class at the specific counter's position (name, user properties...).
If this is not enough (it depends on the application) you can "stick" this counter value at the end of your picture names (kept inside the class): MyPicture00, ThisPicture07, AnyPicture38. So when i.e. an event comes, convert sender's name to char array and keep the last 2 characters (0<=picture_number<100 case). Convert it to int and you will have the counter's value. With this value you know the exact element of the array that triggered the event or you can use this value in a switch-case or do with it whatever you need.

It's a bit low level, but it works.
Dec 28 '09 #9
Hi alexis4, interesting proposal but the resource images arealready preloaded and I just need to sequentially assign them. Does anyone know how to do that please?
Dec 28 '09 #10
tlhintoq
3,525 Expert 2GB
That is just way messy and old-school.

The ResourceManager already knows all the resources let's just ask it.
Resources are kept on a per-culture basis. This is so you can make your program culture-specific. You can have resources if you deploy in English, a different set for Spanish and so on. We are simply going to get all the resources for English in this case.

Expand|Select|Wrap|Line Numbers
  1. System.Resources.ResourceSet temp = Properties.Resources.ResourceManager.GetResourceSet(new CultureInfo("en-US"), false,false);
  2. if (temp == null)
  3. {
  4.     // No resources specific to English
  5.     // Look for other resourses in the language of your application
  6. }
  7. foreach (System.Collections.DictionaryEntry set in temp)
  8. {
  9.     Console.WriteLine(string.Format("{0}: {1}", set.Key, set.Value));
  10. }
Try running this. It will show you the full list of resources and their types. From there you can sort a list, throw out ones that don't start with the word "card" for example etc.
Dec 28 '09 #11
Thanks again tlhintoq, another great step towards my desired goal but I was wondering if the GetEnumerator property could be used in my loop and if so how would I do that please? Unfortunately I am unaware of how to use it although the IDE advises me that is can iterate through the resource set?
Dec 28 '09 #12
tlhintoq
3,525 Expert 2GB
At this point I'm going to recommend experimentation and the MSDN.
Dec 28 '09 #13
Okay tlhintoq, thanks for your help. :)
Dec 29 '09 #14

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Chris | last post by:
Visual Studio 2003 Windows XP SP2 Problem: I have lost my original xyz.bmp file. However it is still available in my app because they get copied into the ..resx file and stores as a base64...
0
by: Jin P via .NET 247 | last post by:
how you guys embed an audio file (let say wav format) in a resx file? I can embed images but somehow when I try to embed audios, it said out of memory. -------------------------------- From: Jin...
1
by: Hiten | last post by:
Hi i have created one .resx file for adding 38 Images............... after creating it when i open it and reads it through IDictionaryEnumerator or by using DictionaryEntry structure i am not...
0
by: David Krussow | last post by:
I had an aspx page (mypage.aspx) with a code behind file (mypage.aspx.cs) that in turn had a resx file (mypage.aspx.resx). I decided to create another aspx page (myotherpage.aspx) that would reuse...
6
by: Crirus | last post by:
Hi there I have an application that I use to add images toa resx file The strange thing is that when I retrive the image and use in my application, all pics a re zoomed in and then cropped, so...
0
by: prabhupr | last post by:
Hi Folks I'm currently working on a Localization+Globalization project; for this project, we need to generate ".Resx" files and we use "US English" Resx file as the base version, to compare the...
0
by: Steave | last post by:
Hi, using Managed C++ (.Net 2.0), I want to embed some images within an executable using a .resX file, and upon an event (in this case a combo box changing), I want the picture box to update with a...
1
by: CKKwan | last post by:
Dear All, When creating a new ASPNET project in VS2008, everything looks good. But when migrating from VS2003 to 2008 (or even VS2005) VS will create a *.resx file along with each and every...
8
by: raylopez99 | last post by:
I have the latest version of Visual Studio 2008 Professional, which allows you to create resource files (this is the .resx file, no?), unlike the Express version, which does not. I am trying to...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.