CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    26

    Script Colors in Text Editor

    What is the simplest way to make a text editor "color" spefic words, AND, even if you load a file containing these words it should auto color them in the color wanted.

    I've downloaded a script before and learned how to do it, but is there a simple way to understand how the procedure is written? And how to make it check up words when you load a file into the editor.

  2. #2
    Join Date
    Dec 2001
    Posts
    6,332

    Re: Script Colors in Text Editor

    Perhaps the easiest way would be to use a RichTextBox. If you use spaces as a delimiter, you can scan through the text in a loop and set the color as desired. That requies selecting the text with the SelStart and SelLength properties of the box, and setting the SelColor property.
    Please remember to rate the posts and threads that you find useful.
    How can something be both new and improved at the same time?

  3. #3
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    26

    Re: Script Colors in Text Editor

    But I need it to change the color to let's say "Blue" when I write "Hello" and if I write "Hello there" only Hello should be colored in blue. Also if I have a text document that I open containing the sentence "Hello there" it should automaticly color the "Hello" word.

  4. #4
    Join Date
    Dec 2001
    Posts
    6,332

    Re: Script Colors in Text Editor

    What you can do is watch for when the user types a space, and that would indicate that the word preceeding the cursor should be checked for coloring. When opening a document you would have to loop through the text. Depending on the specifics, you may be tweeking the code for awhile to get it to work.
    Please remember to rate the posts and threads that you find useful.
    How can something be both new and improved at the same time?

  5. #5
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    26

    Re: Script Colors in Text Editor

    How can I make it check the word that I just wrote? It has to be something like Text.SelLength - 5 (if the word is 5 letters) when you press Space. Or how do you make it look back on what you just wrote? And make a .txt file containing the word to colorize.

  6. #6
    Join Date
    Apr 2005
    Posts
    102

    Re: Script Colors in Text Editor

    I could not find the author or post of this code. I am pretty sure it came from here though.
    Attached Files Attached Files

  7. #7
    Join Date
    Dec 2002
    Location
    London, UK
    Posts
    1,569

    Re: Script Colors in Text Editor

    Quote Originally Posted by superuser
    I could not find the author or post of this code. I am pretty sure it came from here though.
    Just an FYI... incase you want to contact the author... it was me...
    Mike

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured