richTextBox - add text and table

Viewed 7742

i want to add formatted text and table to a richTextBox.

For this I use these codes:

Text:

richTextBox1.SelectionFont = new Font("Maiandra GD", 30, FontStyle.Bold);
richTextBox1.SelectionColor = Color.Red;
richTextBox1.SelectionIndent = 0;
richTextBox1.AppendText("text text text");

And the table:

StringBuilder tableRtf = new StringBuilder();

tableRtf.Append(@"{\rtf1\fbidis\ansi\ansicpg1252\deff0\deflang1033{\fonttbl{\f0\fnil\fcharset0 Microsoft Sans Serif;}}");
for (int j = 0; j <5; j++)
{
    tableRtf.Append(@"\trowd");
    tableRtf.Append(@"\cellx2500" + "  ghhghgjghjghjhggjh");
    tableRtf.Append(@"\intbl\cell");
    tableRtf.Append(@"\cellx10000\intbl\cel");
    tableRtf.Append("   " + "sdfsdfs" + @"\intbl\clmrg\cell\row");
}

tableRtf.Append(@"\pard");
tableRtf.Append(@"}");
richTextBox1.Rtf=tableRtf.ToString();

But the

richTextBox1.Rtf=tableRtf.ToString();

kills the previous contents.

How can I make compatible them?


It is not a duplicate because I want two thing:

1) add formatted text to richTextBox this way:

richTextBox1.SelectionFont = new Font("Maiandra GD", 30, FontStyle.Bold);
richTextBox1.SelectionColor = Color.Red;
richTextBox1.AppendText("text text text");

It is well readable and I can modify easily.

2) And I want to add tables.

So the structure:

text text text text text text text text text text

|TABLE|

text text text text text text text text text text text text text text text

|TABLE|

etc.

But I don't know how can I apply tables without losing previous contents?

1 Answers
Related