enzglk
enzglk

Reputation: 1

How to call an event handler from one control to the another control?

In Visual C# Form Application, When I Click on the button I want to add to the other controls(like listboxes,labels,textboxes) in same form. How do I do this?

Upvotes: 0

Views: 773

Answers (4)

gabba
gabba

Reputation: 2880

If you want to add one event handler to many controls, you can do it.

Just go to properties of control you wish to subscribe, find appropriate event from list (ex: onClick) and choise your existed handler.

But this method will be sutable if events compotable.

Describe your task more detail.

Upvotes: 0

Fredrik Mörk
Fredrik Mörk

Reputation: 158289

You question is somewhat unclear, but if you simply want to access other controls on the form, just go ahead and do so:

private void YourButton_Click(object sender, EventArgs e)
{
    string someValue = yourTextBox.Text;
    // do something with the value
}

Upvotes: 0

Hans Passant
Hans Passant

Reputation: 941227

I have no idea what "to come to the other controls" might mean. But the event handlers in your Form derived class is the switchboard. Implement the button's Click event and have it do whatever you want done with any other controls. A trivial example:

    private void button1_Click(object sender, EventArgs e) {
        label1.Text = "You clicked the button!";
    }

Upvotes: 1

Tim Robinson
Tim Robinson

Reputation: 54724

In the form designer, add an event handler to the button's Click event.

The form designer will give you a new method like this; add your code into this method:

private void button_Click(object sender, EventArgs e)
{
    // Write some code that uses list boxes, labels, text boxes etc.
}

Upvotes: 0

Related Questions