I've got a Picturebox
, the user can select its backgroundimage
out of a resource file.
Later I want to get the resourcename
out of the picturebox
.
I've already tried this:
MessageBox.Show(((PictureBox)sender).BackgroundImage.ToString());
But it gave me the format of the picture.. there isnt something like:
MessageBox.Show(((PictureBox)sender).BackgroundImage.Name.ToString());
and I've already thougt about setting a Tag
to the Picturebox
with the picturename
when setting the Image... but this is annoying as hell...
So how can I get the name of the Resource used as the backgroundimage
at a Picturebox
easily?
I think i have to explain the whole situation:
Ive got a form with a lot of raidbuttons...
if you select one of those buttons and click on a panel,
the panel changes to the selected radiobuttonimage...
the click event of the panel:
PanelClick(object obj ,...)
{
if(radiobuttonApple.checked)
{
obj.backgroundimage = resource.apple;
}
if(radiobuttonPear.checked)
{
obj.backgroundimage = resource.Pear;
}
}
and hundred more of those... and later on i want to know wich resourcefile the backgroundimage is..
Isnt there something like this:
(if i would name the radiobuttons like the resources)
PanelClick(object obj ,...)
{
obj.backgroundimage = resource[selectedradiobutton.Name]
obj.tag = selectedradiobutton.Name
}
So now im about to use LINQ:
RadioButton checkedRadioButton = panel1.Controls.OfType<RadioButton>().FirstOrDefault(r => r.Checked);
obj.tag = checkedRadioButton.Text;
so i only need to know how to get a resource dinamical by name e.g.:
obj.backgroundimage = resource[checkedRadioButton.Text];
and ill use a resourcemanager :
var resman = new System.Resources.ResourceManager(
"RootNamespace.Pictures",
System.Reflection.Assembly.GetExecutingAssembly()
)
var image = resman.GetPicture("checkedRadioButton.Text");
i hope this will work ..