help adding text from richtextbox 1 with richtextbox2 C#

Asked

Viewed 966 times

1

Hello, I would like to know how I do, so when I type in richtextbox1 the text appears in richtextbox2, exactly as if it were a line counter, each time you press enter, only with a number of its own, type a1, A9, b, C4, C5......
see in the image here
Exemplo pratico

1 answer

1

The numbering you say has a logical sequence?

I suggest, put an event in the keypress of your richtextbox1

I transferred the text of rchtb1 to an array (Split breaking the lines at each Enter) for each line I wrote on rchtb2 and broke the line.

private void richTextBox1_KeyPress(object sender, KeyPressEventArgs e)
{
    if (e.KeyChar == 13)
    {
        richTextBox2.Clear();
        string texto = richTextBox1.Text;
        string[] linhas = texto.Split('\n');
        foreach (string linha in linhas)
        {
            richTextBox2.AppendText(linha + Environment.NewLine);
        }
    }
}

If you want to define this sequence, which I did not understand very well, you should put before the variable linha in the richTextBox2.AppendText.

  • Hello, André. Welcome to Stack Overflow. The question is not clear enough and therefore it is not possible to give a good enough answer. When you have enough reputation, you can comment on publications to ask for clarification.

  • the sequence is not logical, it is only finite, has a certain number of "enters", ie, has a limit of lines that can type. thanks for the help @André Alves

Browser other questions tagged

You are not signed in. Login or sign up in order to post.