Allright, I am just for fun making a CSS highlighter of my own, and I want my richtextbox to highlight all Idīs (like #top or #container) it contains, so I have this code when a new Id is entered to turn it red:
CODE
private void brMain_TextChanged(object sender, EventArgs e)
{
//brMain being the richTextBox
string MainText = brMain.Text;
int Starter = 0;
int midler;
int Ender;
do
{
Starter = MainText.IndexOf("#",Starter);
if (Starter < 0)
{ return; }
Ender = MainText.IndexOf("{", Starter);
//Get a length
midler = Ender - Starter;
brMain.SelectionStart = Starter;
brMain.SelectionLength = midler;
brMain.SelectionColor = Color.Red;
//To get a continous flow =)
Starter = Ender;
brMain.SelectionStart = brMain.SelectionStart;
brMain.SelectionLength = brMain.SelectionLength;
}
while (Starter > 0);
}
Now, this, for some reason, colors all the text red.
If I just enter on Id, say "#top { }" it colors only #top, and that's great, but if I add anotherone, say #left, then everything turns red. Somewhere when it loops it decides to select all text and turn it red, and I can't seem to understand WHERE is does this or why. Now, I'm quite new to RTB, so I might have missed something very important.
Anyone had this experiance?