I'm making a log system for a program im creating and I currently have it to where it does this:
void outToLog(string output)
{
logRichTextBox.AppendText(output + "\r\n");
logRichTextBox.ScrollToCaret();
}
But it ends up outputting the last line of the RichTextBox as blank (because I'm using \n) and I want the last line to just be whatever the output was, not a blank line. An alternative was for me to put the "\r\n" at the beginning, but this just has the same affect except its at the beginning of the RichTextBox.
help? thanks
Append the text after the newline.
void outToLog(string output)
{
logRichTextBox.AppendText("\r\n" + output);
logRichTextBox.ScrollToCaret();
}
If you don't want the newline at the start, check the TextBox for empty text and only add the \r\n when the TextBox is not empty.
void outToLog(string output)
{
if(!string.IsNullOrWhiteSpace(logRichTextBox.Text))
{
logRichTextBox.AppendText("\r\n" + output);
}
else
{
logRichTextBox.AppendText(output);
}
logRichTextBox.ScrollToCaret();
}
Eh, why not check? If text box is empty - just put the output, but if text box is not empty, add a new line and then append the the output.
void outToLog(string output)
{
if (String.IsNullOrEmpty(logRichTextBox.Text))
logRichTextBox.AppendText(output);
else
logRichTextBox.AppendText(Environment.NewLine + output);
logRichTextBox.ScrollToCaret();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With