I am using the System.Windows.Forms.RichTextBox control in .NET 2.0 and am using c#.
I have an array of strings that I would like to append to the RichTextBox, but I do not want to create new paragraphs in the RTF. I want the lines to be divided by \line commands, not \par commands in the RTF. (I want to simulate someone typing shift+enter instead of just enter.)
I have not been able to successfully get RichTextBox.AppendText to generate a \line command instead of a \par command. So I have been inserting my text and then manually inserting the \line command into the RTF itself.
This fails when one of the strings contains characters that are escaped in the RTF (a single closequote is converted to \rquote for example) because I am not able to find the original string I inserted into the RTF.
With this solution, I will need to escape out the characters in my line before searching for it in the RTF.
Is there a way to get the RichTextBox control to generate the \line command and not the \par command or will I have to stick with this solution and search for the RTF escaped string.
Here is my current code:
string[] lines = textInfo.Lines;
for (int i = 0; i < lines.Length; i++)
{
rtb.AppendText(lines[i]);
if (i < lines.Length - 1)
{
string rtf = rtb.Rtf;
int insertedIndex = rtf.LastIndexOf(lines[i]);
int length = lines[i].Length;
rtf = rtf.Insert(insertedIndex + length, @"\line");
rtb.Rtf = rtf;
}
}