Hi friends!
I'm doing a small project in VC# 2008.
In the main form (called myForm) I have a richTextBox (called myRichTextBox) and a button (called myButton). The thing is: when I click on the button, the last line from the richTextBox must be deleted. I'm doing like this:
private void myButton_Click(object sender, EventArgs e)
{
if (myRichTextBox.TextLength != 0)
{
int totalCharacters = myRichTextBox.Text.Trim().Length;
int totalLines = myRichTextBox.Lines.Length;
string lastLine = myRichTextBox.Lines[totalLines - 1] + "\n";
string copyOfLastLine = myRichTextBox.Lines[totalLines - 1];
if (totalLines > 1)
{
string newstring = myRichTextBox.Text.Substring(0, totalCharacters - lastLine.Length);
myRichTextBox.Text = newstring;
}
else
{
myRichTextBox.Text = "";
}
}
}
Ok! So it's working well when there's not a blank line in the richTextBox. Otherwise it wouldn't.
I really need hepl. I was working on it 3 days. No good result.
Thanks in advanced!