How to add a line to a multiline TextBox?

后端 未结 10 642
情话喂你
情话喂你 2020-12-01 15:32

How can i add a line of text to a multi-line TextBox?

e.g. pseudocode;

textBox1.Clear();
textBox1.Lines.Add(\"1000+\");
textBox1.Lines.Add(\"750-999\         


        
10条回答
  •  忘掉有多难
    2020-12-01 16:01

    I would go with the System.Environment.NewLine or a StringBuilder

    Then you could add lines with a string builder like this:

    StringBuilder sb = new StringBuilder();
    sb.AppendLine("brown");
    sb.AppendLine("brwn");
    
    textbox1.Text += sb.ToString();
    

    or NewLine like this:

    textbox1.Text += System.Environment.NewLine + "brown";
    

    Better:

    StringBuilder sb = new StringBuilder(textbox1.Text);
    sb.AppendLine("brown");
    sb.AppendLine("brwn");
    
    textbox1.Text = sb.ToString();
    

提交回复
热议问题