David12 David12 - 3 years ago 237
C# Question

C# make Event to RichTextBox in TabControl

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.

Answer Source

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  ... 
 };
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download