Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The RichTextBox control automatically updates the Text and Rtf properties when you modify either of them. Any text appended to the Text property will automatically be updated to the RTF property.</p> <p>From some quick testing, it seems the RichTextBox control automatically inserts \par to any newline (enter, shift-enter on the control and \r \n \r\n Environment.NewLine on the Text property and the AppendText() function on the control itself). Which is what you report as your problem.</p> <p>I don't believe there is any way to change how the control generates RTF. I would just append the text and let the RichTextBox control handle the conversion of any characters that may need escaping and then replace all the \par with \line.</p> <p>Assuming textInfo is a TextBox and you want to append its contents to the end of some already existing RTF (if not replace += for = in line 1</p> <pre><code>rtb.Text += textInfo.Text; rtb.Rtf = rtb.Rtf.Replace(@"\par", @"\line"); </code></pre> <p>Edit:</p> <p>Since you're appending lines to your document line by line, and you know the control generates a \par for \r\n, you could postfix some unique text(you can get creative here, I used REPLN) to the lines you want to break with a \line. Of course, you'd have to be able to identify the lines you want to be replaced, which I assume you do from your question. After appending your unique text, you can then replace again REPLN\par with \line. Not as elegant as I would have liked, but it gets the job done.</p> <pre><code>foreach (string line in textInfo.Lines) { //assuming your condition is that the string contains the substring, "substring" rtb.AppendText(line + (line.Contains("substring") ? "REPLN\r\n" : "\r\n")); } rtb.Rtf = richTextBox1.Rtf.Replace(@"REPLN\par", @"\line"); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload