How to replace a line break of a richTextBox with a space c #

2

Good morning ... I have a richTextBox in which I enter a text then that text I pass it to string , then that same string I put it in textbox . But when I assign that string to textbox the line breaks that I added with the enter key do not appear and the text comes out together.

this is the code of the "Pasar texto" button

string texto = richTextBox1.Text;
textBox1.Text = texto;
    
asked by jose marquez 17.11.2016 в 18:12
source

1 answer

2

Good day, you have to have several considerations, first that all the TextBox must have the property Multiline in true .

textBox1.Multiline = true;

You can also modify property from the Visual Studio Design.

Now, line breaks are handled differently in each control, in RichTextBox are handled by "\n" , while in TextBox have the form "\r\n" . Here is the code for how to solve your problem

string texto = richTextBox1.Text;
texto = texto.Replace("\n", "\r\n");
textBox1.Text = texto;
    
answered by 17.11.2016 / 18:24
source