Franchette Camoro
Franchette Camoro

Reputation: 80

one of several controls may be clicked but all have the same code

im doing a windows form on c#. I have a groupPanel1 and in it are 7 textboxes. Whenever i click on any textbox that is in the group panel, the button save (btnSave) outside the panel is enabled. Is there a way to have an array or create a custom event where i click any of the textboxes or the panel will result to enabling the save button? or whatever helps.

 private void groupPanel1_Click(object sender, EventArgs e)
    {
        btnSave.Enabled = true;
    }

Upvotes: 1

Views: 38

Answers (2)

H W
H W

Reputation: 2586

You were probably looking for something like this: Handling a Click for all controls on a Form ?

For your case you won't need the recursive call since all textboxes are contained in your groupPanel and you only need to assign the handler to textboxes instead of all available controls. Meaning the following (untested) code in your form_load event should do the trick.

foreach (Textbox t in groupPanel1.Controls.OfType<TextBox>())
{
t.MouseClick += new MouseEventHandler(
  delegate(object sender, MouseEventArgs e)
  {
    btnSave.Enabled = true;
  };
}

Upvotes: 0

Michel Keijzers
Michel Keijzers

Reputation: 15357

You can set the click event of each of the textbox to the same method (enabling the button).

Upvotes: 1

Related Questions