-2

I make RichTextBox in TabControl:

private void newModuleToolStripMenuItem_Click(object sender, EventArgs e) {
  TabPage tab = new TabPage();
  RichTextBox richText = new RichTextBox();

  string promptValue = ShowDialog("Input File Name", "File name");

  tab.Text = promptValue;
  tabControl1.Controls.Add(tab);
  tabControl1.SelectTab(tabControl1.TabCount - 1);

  richText.Parent = tabControl1.SelectedTab;
  richText.Dock = DockStyle.Fill;

}

and I would to make event TextChange to this RichTextBox.

xGeo
  • 2,149
  • 2
  • 18
  • 39
David12
  • 61
  • 5
  • 1
    Possible duplicate of [how to add an event to a UserControl in C#?](https://stackoverflow.com/questions/3486377/how-to-add-an-event-to-a-usercontrol-in-c) – rweisse Sep 30 '17 at 10:00

1 Answers1

0

You can just add the following to newModuleToolStripMenuItem_Click code:

richText.TextChanged += RichText_TextChanged;

Then define the event handler:

private void RichText_TextChanged(object sender, EventArgs e)
{
   // add your handling code here  ...
}

Or you can make your event handler in lambda expression:

richText.TextChanged += (sender, e) =>
 {
    // add your handling code here  ... 
 };
Abdullah Dibas
  • 1,499
  • 1
  • 9
  • 13