How to change color of newly added text in Rich Text field

Consider that my Windows application, built using C # VS 2005, displays certain content in a Rich Text Box. Now when I add new text, it should appear in a different color. ie I need to distinguish between the text that is displayed programmatically and the text that I entered into the textbox. How can i do this?

Otherwise, the font color of the newly inserted text must be different from the text that is already displayed.

PS: I used to use a textbox and change it to a rich textbox as said in the downstream. link text

+1


a source to share


2 answers


private void richTextBox1_KeyPress(object sender, KeyPressEventArgs e)
    {            
        this.richTextBox1.SelectionColor = Color.Red;
    }

      



Text pasted with keyboard is red.

+1


a source


IIRC, this works:



  • Set the selection start index to the last character.
  • Change selection color.
  • Add new text.
  • Reset selection color.
0


a source







All Articles