Multiple Controls

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Thom Little

    Multiple Controls

    Using Windows Form C# in .NET 3.5

    I have 12 controls on a form. When one of them is clicked I want a common
    event handler to do the processing and substitute a single property on the
    form. There is a different value for the property in each control.

    Is there a standard way to determine which control was clicked and to make a
    substitution like this one? Can you point me to an example?

    .... Thom
    _______________ _______________ _______________ ______
    Thom Little - www.tlanet.net - Thom Little Associates, Ltd.
  • Marc Gravell

    #2
    Re: Multiple Controls

    You can find which button was called by casting "sender" to Button.
    For the property, well - I guess Tag would be a suitable place to
    store extra info - i.e. set the Tag of each button to the required
    value:


    void SharedHandler(o bject sender, EventArgs args) {
    Button btn = sender as Button;
    if(btn == null) return; // wtf?
    this.SomeProper ty = (string)btn.Tag ; // subst with desired type of
    SomeProperty
    }

    Comment

    • Marc Gravell

      #3
      Re: Multiple Controls

      (oh, replace "Button" with "Control" if you meant any control; I had
      Button on the brain...)

      Comment

      • Thom Little

        #4
        Re: Multiple Controls

        I was not seeing it ... it is now working thanks to your message.

        Thanks for the help.

        .... Thom
        _______________ _______________ _______________ ______
        Thom Little - www.tlanet.net - Thom Little Associates, Ltd.

        Comment

        Working...