AverageWriter
Member
- Joined
- Dec 30, 2021
- Messages
- 10
- Programming Experience
- Beginner
Hi!
I'm a beginner at C#, so I'm sure this is a pretty easy question for most to answer. I've searched high and low and haven't been able to come up with an answer though.
So I'm designing a program that takes a series of tiles (all saved in individual resource files from 1 to 30) and dynamically allocates them to a series of image controls.
So far so good- using global::WorldDesigner.Properties.Resources._1 (where _1 is the resource name) allows me to assign individual images.
The problem is that I need to dynamically allocate them.
In other words, I have a loop set up that needs to change that "1" to a "2" and so on, each time populating the appropriate control, until the loop finishes.
I have a pair of strings set up that combines the first part of the path (global::WorldDesigner.Properties.Resources._) with the appropriate number (1, 2, etc)
The problem I'm having is taking that finished string and then turning it back into a path, so the program thinks that my stringCombined string is a valid path to assign to the image.
What do you all think would be the best solution?
I've got a small block of code; this throws out an error.
I'm a beginner at C#, so I'm sure this is a pretty easy question for most to answer. I've searched high and low and haven't been able to come up with an answer though.
So I'm designing a program that takes a series of tiles (all saved in individual resource files from 1 to 30) and dynamically allocates them to a series of image controls.
So far so good- using global::WorldDesigner.Properties.Resources._1 (where _1 is the resource name) allows me to assign individual images.
The problem is that I need to dynamically allocate them.
In other words, I have a loop set up that needs to change that "1" to a "2" and so on, each time populating the appropriate control, until the loop finishes.
I have a pair of strings set up that combines the first part of the path (global::WorldDesigner.Properties.Resources._) with the appropriate number (1, 2, etc)
The problem I'm having is taking that finished string and then turning it back into a path, so the program thinks that my stringCombined string is a valid path to assign to the image.
What do you all think would be the best solution?
I've got a small block of code; this throws out an error.
C#:
private void timer1_Tick(object sender, EventArgs e)
{
int currentTile = TileBar.Value;
int TileIndex = 0;
var stringLeft = TileBar.Value.ToString();
string stringCombined = "";
var stringCombined2 = "";
int TileCounter = 1;
for (TileCounter = 0; TileCounter < 30; TileCounter++) // begins the loop
{
stringCombined = "global::WorldDesigner.Properties.Resources._" + TileCounter; // this creates the icon value to assign to the designer //
stringCombined2 = "TileRef" + stringLeft; // this gets the current icon to assign to //
TileRef1.Image = stringCombined; // this is where the error is thrown
}
}
Last edited by a moderator: