Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have a problem about showing data in RichTextBox by selected tab, but I don't need to show in the selected tab, I need show by RichTextBox for run.

C#
private void btn_Runserver_Click(object sender, EventArgs e)
{
   AddTab();
   StartCMD();

}

private void AddTab()
{
    TabPage newTab = new TabPage((string)cbConfig.SelectedItem);

    RichTextBox rtb = new RichTextBox();

    rtb.Dock = DockStyle.Fill;
    rtb.ScrollBars = System.Windows.Forms.RichTextBoxScrollBars.Vertical;
    rtb.BorderStyle = System.Windows.Forms.BorderStyle.None;
    rtb.BackColor = System.Drawing.Color.White;
    rtb.ReadOnly = true;

    newTab.Tag = rtb;
    newTab.Name = (string)cbConfig.SelectedItem;
    newTab.Controls.Add(rtb);

    tabControl.Controls.Add(newTab);
    tabControl.SelectTab(newTab);
}

private void build_ErrorDataReceived(object sender, DataReceivedEventArgs e)
{
    string strMessage = e.Data;
    if (tabControl.InvokeRequired)
    {
        tabControl.Invoke(new Action(() =>
        {
            RichTextBox rtb = (RichTextBox)tabControl.SelectedTab.Tag;
            rtb.AppendText(strMessage + Environment.NewLine);
            rtb.Select(rtb.Text.Length - 1, 0);
            rtb.ScrollToCaret();
        }));
    }
}


Code RunCMD Form

C#
proc.OutputDataReceived += build_ErrorDataReceived;
proc.BeginOutputReadLine();


Now my problem is that if I run the program and data show in RichTextbox by selected tab, but I need to show data in RichTextbox On RichText Tab Safe

Someone said "change RichTextBox rtb = (RichTextBox)tabControl.SelectedTab.Tag;, don't use SelectedTab", but I not know how to change it accordingly.
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900