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. color change

color change

Scheduled Pinned Locked Moved Managed C++/CLI
data-structureshelptutorial
2 Posts 2 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 am trying to change the color of a word, while typing itself, for that i wrote the code as follows. private: System::Void keypressevent(System::Object^ sender, System::Windows::Forms::KeyPressEventArgs^ e) { array<String^>^ keyword = gcnew array<String^>{"#include","#define","struct"}; int length = keyword->Length; String ^ strRTF = this->richTextBox1->Rtf; this->richTextBox1->Clear(); 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; int keylen; int iRTFLoc; bool found = false; bool starcomment = true; int nlen = strRTF->Length; for(int nchRTF = 0;nchRTF < nlen;nchRTF++) { if(strRTF[nchRTF] == ' ') { for(int nkeyword = 0;nkeyword<length;nkeyword++) { key = keyword[nkeyword]; keylen = key->Length; iRTFLoc = tempst->IndexOf(keyword[nkeyword]); if(tempst == 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, strRTF[nchRTF]); result = String::Concat(result,tempst); tempst = String::Empty; } else { tempst = String::Concat(tempst,strRTF[nchRTF] ); } } result = String::Concat(result,tempst); tempst = String::Empty; this->richTextBox1->Rtf = result; } Now my problem is when i am typing the code in the richtextbox it will be displayed like "diov" instead of "void". I i think its cursor position problem. can you tell me how to recover this.

    M 1 Reply Last reply
    0
    • R rose196

      Hai I am trying to change the color of a word, while typing itself, for that i wrote the code as follows. private: System::Void keypressevent(System::Object^ sender, System::Windows::Forms::KeyPressEventArgs^ e) { array<String^>^ keyword = gcnew array<String^>{"#include","#define","struct"}; int length = keyword->Length; String ^ strRTF = this->richTextBox1->Rtf; this->richTextBox1->Clear(); 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; int keylen; int iRTFLoc; bool found = false; bool starcomment = true; int nlen = strRTF->Length; for(int nchRTF = 0;nchRTF < nlen;nchRTF++) { if(strRTF[nchRTF] == ' ') { for(int nkeyword = 0;nkeyword<length;nkeyword++) { key = keyword[nkeyword]; keylen = key->Length; iRTFLoc = tempst->IndexOf(keyword[nkeyword]); if(tempst == 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, strRTF[nchRTF]); result = String::Concat(result,tempst); tempst = String::Empty; } else { tempst = String::Concat(tempst,strRTF[nchRTF] ); } } result = String::Concat(result,tempst); tempst = String::Empty; this->richTextBox1->Rtf = result; } Now my problem is when i am typing the code in the richtextbox it will be displayed like "diov" instead of "void". I i think its cursor position problem. can you tell me how to recover this.

      M Offline
      M Offline
      Mark Salsbery
      wrote on last edited by
      #2

      What does the cursor have to do with any of this code? I'm curious if you know what any of this code does or if you're just using snippets of code obtained from others without knowing how it works... :confused: If you post code in a readable format (use the PRE tags!) you may get more and/or better responses here. Mark

      Mark Salsbery Microsoft MVP - Visual C++ :java:

      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