c# - How can you append a \line, not a \par to a System.Windows.Forms.RichTextBox -


I am using System.Windows.Forms.RichTextBox control in .NET 2.0 and using C # .

I have a string in which I want to add a rich textbox, but I do not want to create a new paragraph in RTF. I want lines to be divided by \ line commands, not \ par command in RTF (I want to enter a typing change instead of just entering it.)

I have successfully received the RichTextBox I'm not able. AppendText to generate a line command rather than a \ param command. That's why I am inserting my text and then manually applying the \ line command in the RTF itself.

This fails when one of the characters in the string is RTF (a single stop expression \ rquote for example) because I can not put the original string in RTF.

With this solution, I have to extract the characters in my line before searching for it in RTF.

There is no control to generate the RichTextBox control \ line command and there is no \ param command or I have to live with this solution and will have to search for the string avoiding the RTF.

Here is my current code:

  string [] rows = text interpreting Lines; (Int i = 0; i & lt; lines.Length; i ++) for {rtb.AppendText (line [i]); If (I and LT; lines. Length - 1) {string rtf = rtb.Rtf; Int insertedIndex = rtf.LastIndexOf (line [i]); Int length = lines [ii]. Lamps; Rtf = rtf.Insert (insert index + length, @ "\ line"); RTB. RTF = RTF; }}  

Rich textbox control automatically updates text and RTF properties when you them. Any text added in the text property will automatically update to the RTF property.

With some quick testing, it seems that the RichTextBox controls the control automatically on any new line (enter the control, enter the entry and \ r \ n \ r \ nthe text AnneNline on property and on the Appendect () function for control. What you report as your problem is that.

I do not think there is any way to control the control how the control produces RTF. I will just add the text and the Rich Textbox control handles the conversion of any letter that may need to be avoided. And then all the lines \ par \ \ \ \ \

Assume that TextInfo is a text box and you want to add it to the content of the already existing RTF (if + = for = = in line 1

  rtb.Text + = textInfo.Text; rtb.rtf = rtb.Rtf.Replace (@ "\ Par", @ "\ line");  

Edit: < / P>

Since you add a line to your document line from the line, and you know the control \ r \ n, you can post a unique text, I can use, I have used RPLN) The line you want to break from the line, of course, you must be able to identify those rows. Missed since you want to change, which add I think you tend to your question. Its unique text, then you can replace REPLN \ par the \ line. Not as elegant as I liked, but it did the job.

  foreach (textinfo.low string row in lines) {// your condition assuming that substrings in the string, "substring" would be rtb.AppendText (line + (line.Contains ("substring") Is "REPLN \ r \ n": "\ r \ n")); } Rtb.Rtf = richTextBox1.Rtf.Replace (@ "REPLN \ par", @ "\ line");  

Comments

Popular posts from this blog

c++ - Linux and clipboard -

Visual Studio 2005: How to speed up builds when a VSMDI is open? -

booting ubuntu from usb using virtualbox -