keyword color change
-
Hai, I just want to change the color of certain keyword, while typing itself, for that i am using the rtf format. For this which event handler shall i use. if i use textchange event it shows the error as follows. An unhandled exception of type 'System.StackOverflowException' occurred in System.Windows.Forms.dll My code is as follows. private: System::Void lettertyped(System::Object^ sender, System::EventArgs^ e) { array<String^>^ keyword = gcnew array<String^>{"#include","#define","struct","int","char","void","float","double","longint","long","if","else","true","false","return"}; int length = keyword->Length; String ^ strRTF = this->richTextBox1->Rtf; int iCTableStart = strRTF->IndexOf("colortbl;"); if (iCTableStart != -1) { int iCTableEnd = strRTF->IndexOf('}', iCTableStart); strRTF = strRTF->Remove(iCTableStart, iCTableEnd - iCTableStart); strRTF = strRTF->Insert(iCTableStart, "colortbl ;\\red255\\green0\\blue0;\\red0\\green128\\blue0;\\red0\\green0\\blue255;}"); } else { int iRTFLoc = strRTF->IndexOf("\\rtf"); int iInsertLoc = strRTF->IndexOf('{', iRTFLoc); if (iInsertLoc == -1) iInsertLoc = strRTF->IndexOf('}', iRTFLoc) - 1; strRTF = strRTF->Insert(iInsertLoc, "{\\colortbl ;\\red128\\green0\\blue0;\\red0\\green128\\blue0;\\red0\\green0\\blue255;}"); } int len = strRTF->Length; String^ tempst; String^ result; String ^key; //String ^strReplace; String ^slash = "/*"; String ^endslash = "*/"; String ^commentlinestr = "//"; char startquots = '"'; char endquots = '"'; int keylen; int iRTFLoc; int intslash; int stquotes; //int endquotes; int commentline; bool found = false; bool spacefound = false; bool starcomment = true; bool slashcomment = false; bool endquot = false; int nlen = strRTF->Length; for(int nchRTF = 0;nchRTF < nlen;nchRTF++) { if(strRTF[nchRTF] == ' ' || strRTF[nchRTF] == '\n' || strRTF[nchRTF] == '"' || strRTF[nchRTF] == ';' || strRTF[nchRTF] == '(' || strRTF[nchRTF] == ',' /*|| strRTF[nchRTF] == '*' */) { //Keyword for(int nkeyword = 0;nkeyword<length;nkeyword++) { key = keyword[nkeyword]; keylen = key->Length; iRTFLoc = tempst->IndexOf(keyword[nkeyword]); if(/*iRTFLoc >= 0*/ tempst->Contains(key)) { found = true; break; } } if(found) { if(starcomment) { int location = 4+iRTFLoc+keylen+1; tempst = tempst->Insert( iRTFLoc,"\\cf3 "); tempst = tempst->Insert( location,"\\cf0 "); } found = false; } tempst = String::Concat(tempst,