Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Managed C++/CLI
  4. keyword color change

keyword color change

Scheduled Pinned Locked Moved Managed C++/CLI
data-structureshelp
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    rose196
    wrote on last edited by
    #1

    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,

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups