I want to load the image like this:
void info(string channel)
{
//Something like that
channelPic.Image = Properties.Resources.+channel
}
Because I don’t want to do
void info(string channel)
{
switch(channel)
{
case "chan1":
channelPic.Image = Properties.Resources.chan1;
break;
case "chan2":
channelPic.Image = Properties.Resources.chan2;
break;
}
}
Is something like this possible?
You can always use
System.Resources.ResourceManagerwhich returns the cachedResourceManagerused by this class. Sincechan1andchan2represent two different images, you may useSystem.Resources.ResourceManager.GetObject(string name)which returns an object matching your input with the project resourcesExample
Notice:
Resources.ResourceManager.GetObject(string name)may returnnullif the string specified was not found in the project resources.Thanks,
I hope you find this helpful 🙂