private void richTextBox1_TextChanged(object sender, EventArgs e) { richTextBox2.Text = ""; richTextBox1.SelectionAlignment = HorizontalAlignment.Left; for (int i = 1; i < richTextBox1.Lines.Length; i++) { richTextBox2.Text += i.ToString() + '\r' + '\n'; } var currentSelStart = richTextBox1.SelectionStart; var currentSelLength = richTextBox1.SelectionLength; richTextBox1.SelectAll(); richTextBox1.SelectionColor = SystemColors.WindowText; bluend blue_obj = new bluend(); Yellow yellow_obj = new Yellow(); Orange orange_obj = new Orange(); blue_obj.check(richTextBox1); yellow_obj.check(richTextBox1); orange_obj.check(richTextBox1); richTextBox1.Select(currentSelStart, currentSelLength); richTextBox1.SelectionColor = SystemColors.WindowText; }