How to show the "New line" command in a text box?

Hi, I am doing a small project in C # and I need to know which commands are sent from the input source, so I can do my job accordingly. here is an example ...

textBox1.Text = "First line \nSecond line"; richTextBox1.Text = "First line \nSecond line"; 

Richtextbox shows this output:

First line

Second line

The text box shows this output:

First line Second line

tell me how to show a new line "\ n" or return "\ r" or similar input as character output in text or richtextbox. so I can know that the newline command comes from the input.

for example, text or rich text will display this output.

First line \ n Custom line

thankx in advance.

+4
source share
6 answers

Suppose I have a line that has a new line:

  string st = "my name is DK" + Environment.NewLine + "Also that means it my name"; 

Now that I want to show that there is a new line in my text, you:

  textBox1.Text = st.Replace(Environment.NewLine, "%"); 

This will show a new line chat with a% sign

+5
source

For a set of winforms applications

 this.textBox1.Multiline = true; 

and use "\r\n" as

 textBox1.Text = "First line \r\nSecond line"; 
+3
source

You want to either prefix your string with @, or you can use a double slash before each n (\ n). Both of these are escaping methods \ so that it is displayed instead of being processed as part of a new line.

  @"This will show verbatim\n"; "This will show verbatim\\n"; 

You can use this by doing a Replace in your incoming text

 richTextBox1.Text = richTextBox1.Text.Replace("\n", "\n\\n"); richTextBox1.Text = richTextBox1.Text.Replace("\r\n", "\r\n\\n"); 

In the replacement, I left the original line so that it was there, followed by the displayed version. You can take them if you do not want it. :)

+1
source

Use the combination "\ r \ n" (or the Environment.NewLine constant that contains exactly that).

0
source

This is the Image how your text box will appear Change the property of the text field from one line to multi-line, then it will change to a new line

 TextBox1.TextMode = TextBoxMode.MultiLine; TextBox1.Text = "First line \n New line "; 
0
source

TextBoxt1.Text = "FirstLine \ r \ n SecondLine";

0
source

Source: https://habr.com/ru/post/1402805/


All Articles