I'll post a code example to help get you started, but keep mind there are a lot of issues this code doesn't handle, like:
1. when you insert 'int' in a line before the last line of the RichTextBox
2. when you type 'int' at the start of the first line.
To really make any kind of robust word-coloring function, you are going to need to keep track of the words you have colored using some kind of data structure that records their location;
that gets tricky because their location may change any time the user adds new content, or deletes old content, back-spaces, etc.
Think about what would happen if you set the forecolor of an occurrence of "int" to red, and then the user edited the text so that "int" was changed to "in:" clearly, you should be setting the forecolor of "in" back to your default text-color. You can't do that unless you maintain some kind of structure that keeps track of all instances of "int" !
So, do take Dave's advice and study the examples here on CodeProject.
This sample is meant just to give you the idea of saving state (current selection start and selection color), and restoring it after you color a word:
private int currentSelectionIndex;
private Color currentSelectionColor;
private string stringToFind = " int ";
private void richTextBox1_TextChanged(object sender, EventArgs e)
{
int i = richTextBox1.Text.LastIndexOf(stringToFind);
if (i >= 0)
{
currentSelectionIndex = richTextBox1.SelectionStart;
currentSelectionColor = richTextBox1.SelectionColor;
richTextBox1.Select(i, stringToFind.Length);
richTextBox1.SelectionColor = Color.Red;
richTextBox1.SelectionStart = currentSelectionIndex;
richTextBox1.SelectionColor = currentSelectionColor;
}
}