I am trying to add a color table to the RTF of my RichTextBox control when I instantiate the control. The problem is that the color table will not stay there. The only time it stays is if I have text specified in the RTF that is formatted with one of the codes in the color table. That won't work because I don't want text in the control yet. Here is the code and the RTF and the RTF it displays after the line runs:
The RTF that displays is:
{\rtf1\ansi\ans icpg1252\deff0\ deflang1033{\fo nttbl{\f0\fnil\ fcharset0 MS Sans Serif;}}
\viewkind4\uc1\ pard\f0\fs24\pa r
}
I then change the this.outputBox. Rtf line to this:
which outputs this for RTF:
{\rtf1\ansi\ans icpg1252\deff0\ deflang1033{\fo nttbl{\f0\fnil\ fcharset0 MS Sans Serif;}}
{\colortbl ;\red0\green0\b lue0;}
\viewkind4\uc1\ pard\cf1\f0\fs2 4 test\par
}
So if I want to add another color I have to update the color table every time I update the text? Everything I see on the internet says to implement the full color table first. I haven't seen anything about it not staying there if the colors aren't referenced in the text. Please help.
Code:
this.outputBox.Location = new System.Drawing.Point(0, -1); this.outputBox.Name = "outputBox1"; this.outputBox.Size = new System.Drawing.Size(155, 230); this.outputBox.TabIndex = 2; this.outputBox.Text = ""; this.outputBox.Rtf = "{\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang1033" + "{\\fonttbl{\\f0\\fnil\\fcharset0 MS Sans Serif;}}{\\colortbl;\\red0\\green0\\blue0;\\red255\\green255\\blue255;\\red255\\green0\\blue0;\\red0\\green255\\blue0;\\red0\\green0\\blue255;}" + "\\viewkind4\\uc1\\pard\\f0\\fs24\\par}";
{\rtf1\ansi\ans icpg1252\deff0\ deflang1033{\fo nttbl{\f0\fnil\ fcharset0 MS Sans Serif;}}
\viewkind4\uc1\ pard\f0\fs24\pa r
}
I then change the this.outputBox. Rtf line to this:
Code:
this.outputBox.Rtf = "{\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang1033" + "{\\fonttbl{\\f0\\fnil\\fcharset0 MS Sans Serif;}}{\\colortbl;\\red0\\green0\\blue0;\\red255\\green255\\blue255;\\red255\\green0\\blue0;\\red0\\green255\\blue0;\\red0\\green0\\blue255;}" + "\\viewkind4\\uc1\\pard\\f0\\fs24 [B]\\cf1 test[/B]\\par}";
{\rtf1\ansi\ans icpg1252\deff0\ deflang1033{\fo nttbl{\f0\fnil\ fcharset0 MS Sans Serif;}}
{\colortbl ;\red0\green0\b lue0;}
\viewkind4\uc1\ pard\cf1\f0\fs2 4 test\par
}
So if I want to add another color I have to update the color table every time I update the text? Everything I see on the internet says to implement the full color table first. I haven't seen anything about it not staying there if the colors aren't referenced in the text. Please help.