1

How do you make an event dynamically? Like for example, I'm making a notepad with tab support for practice, and for every new tab, a text box is made dynamically. How can I make an event (TextChanged for example) for these text boxes?

Thanks.

Iceyoshi
  • 623
  • 3
  • 10
  • 14

2 Answers2

1

Create an TextBox object, assign the event on it and add to the tab control.

private void button1_Click(object sender, EventArgs e)
{
    tabControl1.TabPages.Add("t1", "new 1");

    var tb = new TextBox();
    tb.TextChanged += (bs, be) =>
    {
        MessageBox.Show("Text has been changed");
    };

    tabControl1.TabPages["t1"].Controls.Add(tb);
}
BrunoLM
  • 97,872
  • 84
  • 296
  • 452
  • @Iceyoshi: Consider marking this answer as accepted if it solves your question. The checkmark on the left. – BrunoLM Oct 16 '10 at 12:54
0

dynamicTextBox.TextChanged += (sender, args) => { your callback code goes here };