Does anybody know how I can write “cardImage1.BorderStyle = BorderStyle.Fixed3D;” without having to explicitly declare “cardImage1”?
I’m trying to put it into a method so that I don’t need to write the code to toggle between two Border Styles when a Picture Box is clicked, for every single single picture box (there are 52!)
e.g. for each box currently I would need to have the following in its _click event.
if (cardImage1.BorderStyle == BorderStyle.None)
{
cardImage1.BorderStyle = BorderStyle.Fixed3D;
}
else
{
cardImage1.BorderStyle = BorderStyle.None;
}
Instead of creating a handler for each picture box, you could write a single method o handle the clicks for all your picture boxes:
You could also write a loop to go over all controls on a form and attac hthe event handler to all picture boxes (if that;s possible in your case)
Of course if you have other picture boxes on the form a solution would be to put the 52 picture boxes you are interested in in a panel and then instead of iterating over all the controls in the form (this.Controls) only iterate over the controls in the panel (thePanelControl.Controls)