Skip to content

How can I set a property associated with a Control onClick when the subroutine is used by multiple Controls?

Joseph Stanish

Asked Apr 13, 2007, 9:44 PM EDT2 answers
Share
LinkedInX

I have several PictureBox controls that all call the same subroutine on a CLICK event.  The Delegate subroutine looks like this: (where sender is the PictureBox control that was clicked.

private void AnyPicture_Click(object sender, EventArgs e) {}

How acheive sender.BackColor = Color.Red when any of several PictureBox controls could have raised this CLICK event?

2 Answers

Know the answer? Post it. Somebody with the same question will find it here.

  • 0
    Code
    
    Hi,
    
    You must cast sender as a PictureBox in order to do so.
    
    ((PictureBox)sender).BackColor = Color.Red;
    
    or 
    
    PictureBox obj = sender as PictureBox;
    obj.BackColor = Color.Red;
    
    Hope this helps!
    Simon
    0
  • 0
    Elegant, simplle, and very sensible! Thanks.
    <question resolved>
    0