private void richTextBox1_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) { generateTextLineContext(richTextBox1.Lines.Length); } if (e.KeyCode == Keys.Back) { generateTextLineContext(richTextBox1.Lines.Length); } } private void generateTextLineContext(int lineNumber) { richTextBox2.ResetText(); for (int i = 1; i <= lineNumber; i++) { richTextBox2.Text += i.ToString() + System.Environment.NewLine; } }