'Need help deleting rows/lines in richtextbox c# win forms

So essentially, I have a button, when I press the button, the button should delete the most recent row of text embedded into the rich text box. Press it again, it should delete the next line above that etc.

I tried a using .substring, which it worked, but required me to double click the button instead of a single click..

Furthermore, when I press the add text button it should replace the deleted line. Currently, the delete button button1_click just removes all lines, but all I want the it to do is remove a line of text from the richtextbox.

Edit: Huge apologies before, I forgot to add the code as mentioned in replies, apologies.

  public partial class Form1 : Form
{
    string[] texts = new string[10];
    int i = 0;
    
    
    public Form1()
    {
        InitializeComponent();
    }

    private void btn_Click(object sender, EventArgs e)
    {
        if (TextBox.Text == "")
        {
            texts[i] = texts[i];
        }
        else
        {
            texts[i] += TextBox.Text + "\r\n";
            richText.Text += texts[i];
            ++i;
            TextBox.Text = "";
        }
        
        
    }

    private void richText_TextChanged(object sender, EventArgs e)
    {
    }

    private void button1_Click(object sender, EventArgs e)
    {
        //i dont know need to do research or im too dumb 
        richText.Text = "";

        for (int i = 0; i < texts.Length; i++)
        {
            texts[i] = "";
        }

        i = 0;

        //https://stackoverflow.com/questions/22587505/delete-the-last-line-of-rich-text-box

        //works, but double click instead of one click

    }
}

}

To clarify, the left button adds text from the textbox and the right button is basically the function aforementioned.

enter image description here

Thanks to anyone who helps!



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source