Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Question
Monday, April 10, 2006 3:12 AM | 1 vote
in my form load event i want to set
\n newline
rtb.Rtf = string1 + \n + string2 + \n + string3
the output should look like this:
string1
string2
string3
All replies (19)
Monday, April 10, 2006 7:27 AM ✅Answered | 5 votes
You should not append flat text to the RichTextBox.Rtf property, only Rich Text Formatter text and still then you need to stay alert so you don't break the format!
Use the RichTextBox.Text property or the RichtTextBox.AppendText method to append a string with a newline.
myRichTextBox.Text += Environment.NewLine + "My new line."; // Or myRichTextBox.AppendText( Environment.NewLine + "My new line." ); |
Tuesday, April 11, 2006 1:00 PM ✅Answered
Then you need to know the RTF protocoll and make your own merge process to merge the RTF texts.
Rich Text Format Specification, version 1.6
Wednesday, April 12, 2006 9:17 AM ✅Answered
No, there is no example. That is the protocol specification, so you can implement this in your merge method.
But there is a easy way, you can copy it character for character but this won't be very fast.
Here is a little example, i have wrote it out of the head but it must point you to the correct direction:
private void button1_Click(object sender, System.EventArgs e) { for( int i = 0; i < richTextBox2.TextLength; i++ ) { string toAppend = richTextBox2.Text[ i ].ToString(); richTextBox1.AppendText( toAppend ); richTextBox1.Select( richTextBox1.TextLength - 1, 1 ); richTextBox2.Select( i, 1 ); richTextBox1.SelectionAlignment = richTextBox2.SelectionAlignment; richTextBox1.SelectionBullet = richTextBox2.SelectionBullet; richTextBox1.SelectionCharOffset = richTextBox2.SelectionCharOffset; richTextBox1.SelectionColor = richTextBox2.SelectionColor; richTextBox1.SelectionFont = richTextBox2.SelectionFont; richTextBox1.SelectionHangingIndent = richTextBox2.SelectionHangingIndent; richTextBox1.SelectionIndent = richTextBox2.SelectionIndent; } } |
Monday, April 17, 2006 3:07 AM ✅Answered
i got it, i added these lines:
if (i == 0)
{
toAppend = "\n\n" + rtb2.Text
.ToString();
}
else
{
toAppend = rtb2.Text
.ToString();
}
Monday, April 10, 2006 4:11 AM | 3 votes
string string1 = "Line 1";
string string2 = "Line 2";
richTextBox1.Text = string1 + System.Environment.NewLine + string2;
Monday, April 10, 2006 4:21 AM
i'm sorry i wasn't clear enough with my problem, what i want to do is to append a Rtf to my rtb.Rtf.
rtb.Rtf += rtfToAppend; // this is not working
Monday, April 10, 2006 5:11 AM
Can you please try with rtb.AppendText("\nLine2") to see if it gets you the desired result?
Monday, April 10, 2006 8:45 AM | 1 vote
got it:
rtb.Rtf = @"{\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl{\f0\fnil\fcharset0 Microsoft Sans Serif;}}" +
@"{\colortbl ;\red128\green128\blue128;}
\viewkind4\uc1\pard\cf1\b\f0\fs24 From:\cf0 \par
\cf1 " + rtfToAppend + @"\par\par}";
thanks for your replies.
Monday, April 10, 2006 10:10 AM
Watch out for breaking the Rtf format!
Tuesday, April 11, 2006 12:00 AM
ok, thanks!
Tuesday, April 11, 2006 2:30 AM
But this only works if I have 1 rtf to append, how about if I have more than one rtf?
Tuesday, April 11, 2006 11:48 PM
i can't find an example in the article. here's what i have, 2 rtb and a button. the user inputs data into the first rtb and then presses enter, rtb1.rtf is assigned to rtb2.rtf if rtb2.textlength == 0 else it is merged or appended to the existing rtb2.rtf.
Monday, April 17, 2006 2:58 AM
thanks for the example, how about if i want to enter characters or newlines between the appended texts?
Tuesday, April 18, 2006 3:41 AM
the appended text from RichTextBox1 loses its format when appended to RichTextBox2.. what should i do to solve this problem? thanks.
Wednesday, April 19, 2006 7:59 AM
In my last example you could see i select the new text and set all the format properties to the value of the source selection.
You have to make sure when you add extra characters to it you don't break the current selection process. The current process always formatted the last character in the destination RichTextBox. Make sure you add extra lines after the formation process.
Tuesday, February 9, 2010 7:13 PM
There is a much easier way...... Ctrl+Enter
Saturday, October 23, 2010 12:45 AM
Either of the following works:
richTextBox.Text += "line " + idx + "\n";
richTextBox.AppendText("line " + idx + System.Environment.NewLine);
But be sure you have richTextBox.Multiline = true
Thursday, December 30, 2010 6:49 AM
Inserting new line as a text format use this.
RTB.Text = "Elayaraja" + "\r\n" + "Sambasivam";
inserting new line by RTF format use this.
RTB.Text = "Elayaraja" + @" \par\r\n " + "Sambasivam";
Monday, May 9, 2016 5:13 PM
Encontré solución en esta forma:
ExcelRichText ert = ws.Cells[y, x].RichText.Add("texto1");
ert.Size = 11;
ert.Bold = true;
//ws.Cells[y, x].Style.WrapText = true;
ert = ws.Cells[y, x].RichText.Add(Environment.NewLine + "texto2");
//ws.Cells[y, x].Style.WrapText = true;
ert.Size = 12;
ert.Bold = true;
Con esa opción puede poner las lineas que desee, ademas puede utilizar diferentes tipos y tamaños de fuente para cada uno.