How to output variables to a rich text box one after the other in c#?

后端 未结 2 1629
轻奢々
轻奢々 2021-01-28 08:31
void ClearAllRichtextboxes()
{
    richTextBox3.Clear();
    richTextBox5.Clear();
    richTextBox6.Clear();
    richTextBox9.Clear();
    richTextBox10.Clear();  
}

Cl         


        
相关标签:
2条回答
  • 2021-01-28 09:00

    You could do something like string formatting to help space the strings with spaces.

    something like

    richTextBox1.Text = String.Format("This is the number of A in B: {0}\r\n This is the number of X in Y: {1}", output1, output2);
    

    \r\n indicates a new line, you can find more information about the String.Format() method on msdn: https://msdn.microsoft.com/en-us/library/system.string.format(v=vs.110).aspx

    0 讨论(0)
  • 2021-01-28 09:10

    Update the richTextBox.Text with the new information. If you want to append the new strings to what is already there use "+". You can save the string as its own variable if it helps.

    richTextBox.Text = "First segment.";  
    richTextBox.Text = richTextBox.Text + " Second segment.";  
    

    More info about string concatenation: https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/strings/how-to-concatenate-multiple-strings

    0 讨论(0)
提交回复
热议问题