RichTextBox and Changing Colours

vb6 Canada
  • 19 years ago

    I'm pretty confident that I know how to change colours in a RichTextBox control. My question is, however, how can I change the text of the textbox where it says certain things? Here's an example:


    I'm making a file editor and I want people to be able to easily distinguish different parts of the code through colour coding. For example, how could I change the colour of text that says (specifically) 'DESCRIPTION' or say I was making a HTML editor and I wanted everything between <!-- and --> to be green. How would I go about doing so?


    Thanks for all your help.

  • 19 years ago

    What you have to do is find the position of that text, and then set SelStart and SelLength, and then change the colour as you would normally do. For an example, take a look at Developers Pad

  • 19 years ago

    I tried looking at the source code but just couldn't find what I was looking for (I know it's there but I couldn't find it). Could someone please just drop me a quick example of how to change the color to a specific line?


    Thanks guys!

  • 19 years ago

    lPos=InStr(0,rtfMain.Text,vbCrLf)
    lEndPos=InStr(lPos,rtfMain.Text,vbCrLf)
    rtfMain.SelStart=lPos
    rtfMain.SelLength=(lEndPos-lPos)
    rtfMain.SelColor=vbRed

  • 19 years ago

    I tried that code but it just makes the whole text red. Is there anyway to make a specific part of the text red, for example, say someone types in the following into my editor (which could be used to editor HTML and/or PHP):




    <somehtmltags>


    <?php
       echo("testtesttest");
    ?>


    </somehtmltags>




    Is there anyway to get the text between say 'echo("' and ') to be say blue while everything else is the default black?


    Sorry to be such a bother, I'm kind of a newbie.

  • 19 years ago

    Take another look at Developers Pad... go to the Editor component (Editor.ctl), and go to the ParseHTMLRange procedure.... Hopefully you might find something of use. I am planning to release a stand-alone component so people can just add it to their programs, but I haven't gotten round to it yet....

Post a reply

Enter your message below

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“There are only 3 numbers of interest to a computer scientist: 1, 0 and infinity”