Last night I was asking how best to add a resource and was given this good advice
"By adding the image files to your resources, you can limit the code needed to display the image to something like this:
pbxCard.Image = Properties.Resources.HeartsQueen;"
But my issue I have now is that I wanted to fill these boxes with Random images chosen by an array.
In other words I want something like pbxCard1 to be the myDeck.cards[0].ToString + ".jpg" image.
By adding my images to the resources like I was told all my images which were named 1 and 2 and 3.jpg (etc.) get their names changed to _1 and _2 and _3 -- so I somehow need to get the number out of the array and then concatenate it to the end.
NOW I KNEW THIS wouldn't work -
pile1image1.Image = Properties.
Resources._ + mydeck.card[0].ToString;but it is in essence what I want to do -- can someone tell me how to do it?
============
ALSO I cant do this:
string
image1 = "Properties.Resources._" + myDeck.cards[0];because when I try and place it into the pile1image1.Image = image1 line - it tells me that I cannot convert a string to an image.... help???


Scott LysleRank #49 · 31K reputationPosted May 30, 2007, 7:54 PM EDT
Sure, you could create an array of images and populate each with one of the card images and then call them using a random number passed as the index value.
Image[] imgs = new Image[51];
imgs[0] = Properties.Resources.Spade2;
imgs[1] = Properties.Resources.Spade3;
imgs[2] = Properties.Resources.Spade4;
imgs[3] = Properties.Resources.Spade5; ...
picBox.Image = imgs[YourRandomNumber];
Todd Vance157 reputationPosted Jun 1, 2007, 9:11 AM EDT
Is there anyway I could automate or iterate that process???
I feel like I am missing something here --- how could I CONCATENATE onto the Properties.Resources.image statement? Is that just NOT possible?
Because if I could, I could simply name the images 1,2,3,4 and then iterate through the array of 52 images -- ???
I tried to type cast using something like this:
string s = "Properties.Resources._" + i;
Image img = s as Image
pbx1.Image = img;
BUT GET THIS - Error 1 Cannot convert type 'string' to 'System.Drawing.Image' via a built-in conversion
====
I can do what Scott suggested but am trying to learn the most efficient ways of programming and having to type out 52 statements manually seems terribly inefficient.