Reputation: 2057
I am populating a form with buttons based on the amount of images in my resources of my application.
I am looping through the images in the resources and foreach image create a button and then set the backgroundimage to the picture.
Now i need to get the image of the button i clicked and pass it to a method. How do i accomplish that?
Thanks in advance.
My code is as follows:
ResourceSet resourceSet = Resources.ResourceManager.GetResourceSet(CultureInfo.CurrentUICulture, true, true);
foreach (DictionaryEntry entry in resourceSet)
{
object resource = entry.Value;
Button b = new Button();
b.BackgroundImage = (Image)resource;
b.BackgroundImageLayout = ImageLayout.Stretch;
b.Bounds = new Rectangle(left, top, buttonSize, buttonSize);
this.Controls.Add(b);
left += buttonSize;
if (left + buttonSize > this.ClientSize.Width)
{
left = 0;
top += 100;
}
b.Click += new EventHandler(buttonClick);
}
Upvotes: 0
Views: 156
Reputation: 6277
Do you mean something like this
protected void buttonClick(object sender, EventArgs args)
{
Button myButton = (Button)sender;
ImageProcessMethod(myButton.BackgroundImage);
}
Upvotes: 2