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!

private void button1_Click_1(object sender, EventArgs e) {
    List<string> myList = richTextBox1.Lines.ToList();
    if (myList.Count > 0) {
        myList.RemoveAt(myList.Count - 1);
        richTextBox1.Lines = myList.ToArray();
        richTextBox1.Refresh();
    }
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.