tying multiple events to one handler:a function with 2 object params

This is my handler function:

   protected static void textChange(object sender,Label labe1, EventArgs e)
        {
            var text = sender as TextBox;
            if (text.Text != "") 
                labe1.Visible = false;
            else
                labe1.Visible = true;
        }

Im trying to do this:

this.textBox1.Click += new System.EventHandler(textChange);

for multiple textboxes.I have tried making both params as objects and then interpreting them as label/textbox inside the function using a variable,ive tried making both of them label/textbox correspondingly in the params declaration.The only way it worked was by having only one object parameter while I need 2.

Jon Skeet
people
quotationmark

Assuming you're trying to associate each text box with a different label, you'll need to write a method that constructs an EventHandler for the relevant label, e.g.

public EventHandler CreateVisibilityHandler(Label label)
{
    return (sender, args) => label.Visible = ((TextBox) sender).Text == "";
}

Then you can use:

textBox1.Click += CreateVisibilityHandler(label1);
textBox2.Click += CreateVisibilityHandler(label2);
// etc

people

See more on this question at Stackoverflow