Need expertise help when using RichTextBox's "TextChanged" event!
Hi every one,
I'm trying to design my own language and it's compiler, I stored the language keywords in a .xml file, use a RichTextBox as an editor in order to make the code "color coded"!
the problem is when use RichTextBox's "TextChanged" event, try this code:
**************************code*************************************
private void richTextBox1_TextChanged(object sender, System.EventArgs e)
{
DataSet ds = new DataSet();
ds.ReadXmlSchema(@"..\..\schema.xsd");
ds.ReadXml(@"..\..\KeyWords.xml");
int start = 0;
System.Text.StringBuilder stBuild = new System.Text.StringBuilder();
for(int i = 0; i < richTextBox1.Text.Length; i++)
{
if(richTextBox1.Text[i] != ' ')
{
stBuild.Append(richTextBox1.Text[i]);
DataRow[] drs = ds.Tables["elements"].Select("keyword = '" + stBuild.ToString() +"'");
if((drs.Length >0) && ((i == richTextBox1.Text.Length -1) || (richTextBox1.Text[i+1] == ' ')))
{
richTextBox1.Select(start, stBuild.Length);
richTextBox1.SelectionColor = Color.Blue;
/*----here, what should I do to return the cursor in the end of the selected word--------*/
}
}
else
{
stBuild.Remove(0,stBuild.Length);
start = i+1;
}
}
}
*******************************************************************
what should I do to return the cursor in the end of the selected word?!
I need expertise help.. Thanks in advance
Manal..