1
Reply

Rich Text Box Syntax Highlighter

Seyed Ahmad Parkhid

Seyed Ahmad Parkhid

Jan 10 2010 1:45 PM
6.4k
What is gonna wrong in this code . i want to Highlight "This" word in rich text box .
I have uploaded the code and also the code is listed below :

        private int SubStr(int start,string a, string b)
        {
            int ret = -1;
            if (a.Substring(start).Contains(b))
            {
                ret = a.IndexOf(b[0]);
            }
            return ret;
        }
        private void richTextBox1_TextChanged(object sender, EventArgs e)
        {

            start = richTextBox1.SelectionStart;
            Pos = SubStr(last, richTextBox1.Text, "This");
            if (Pos != -1)
            {
                richTextBox1.Select(Pos, 4);

                richTextBox1.SelectionColor = Color.Blue;
                richTextBox1.DeselectAll();
                last += 4;
            }
            richTextBox1.SelectionColor = Color.Black;
            richTextBox1.SelectionStart = start;
                   
           
        }


Attachment: SyntaxHiglighter.zip

Answers (1)