C# Color lines in rich textbox from the start of a "#" symbol

108 views Asked by At

So, I am working on a "code editor", and I want to make comments look colorful. I got a solution, however, it's poor. Problems like this happens:

I am a kinda-newbie with c#, so forgive me for my dumb mistakes My code:

        private void richTextBox1_TextChanged(object sender, EventArgs e) {
        int index = richTextBox1.SelectionStart;
        int line = richTextBox1.GetLineFromCharIndex(index);
        this.CheckKeyword("#", Color.Green, 0);
        if(richTextBox1.Lines[line].StartsWith("#")) {
            richTextBox1.Select(index, richTextBox1.Lines[line].Length);
            richTextBox1.SelectionColor = Color.Green;
            richTextBox1.Select(index, 0);
            return;
        }
        this.CheckKeyword("while", Color.Purple, 0);
        this.CheckKeyword("if", Color.Green, 0);
    }

EDIT: http://pastebin.com/aztYGqf9 Using this code now, everything's working, except that new lines can be affected too to be green. http://prnt.sc/dsbpvu

0

There are 0 answers