Page 1 of 1

Richtextbox Color Syntax Help(VB)

Posted: Fri Dec 28, 2007 2:41 am
by jebtrillion
Hello everyone

I would like a richtextbox have multiple colors in it.

To go into more detail:

I want certain tags to be different colors.

Lets says for every string in the richtextbox that is the following text "Pluigin" make it blue.

I want to end up with somthing that looks like visual basics color syntax.


Thanks

Posted: Fri Dec 28, 2007 4:59 pm
by xzodia
ooo i tried this a while ago but never got it to work so i'll be interested if anyone has the answer

Posted: Sat Dec 29, 2007 4:24 am
by Patrickssj6
Same here

Posted: Sat Dec 29, 2007 5:25 am
by bcnipod
I know how to do it in Cocoa, but not VB

Posted: Sat Dec 29, 2007 8:22 am
by Prey
It's very difficult to "explain".. You've basically got to think very logically about it.

To actually change the colour of a piece of text in the richtextbox..

Code: Select all

Dim start As Integer = rtb.SelectionStart
Dim length As Integer = rtb.SelectionLength
rtb.SelectionStart = 0 ' Index of start of word
rtb.SelectionLength = 10 ' Length of word
rtb.SelectionColor = Color.DarkRed
rtb.SelectionStart = start
rtb.SelectionLength = length
You will notice though that this does actually make the RTB 'flicker', where for a brief moment you see the highlight drawn over the text to be changed. This can be avoided by overriding the RTB and keeping control of when to let it re-paint. There should be something on the internet to help you with that.. just search for 'flicker free RTB' or something.

Posted: Wed Aug 06, 2008 5:19 am
by jebtrillion
For anyone who was interested in this I have found some really useful code.

Here it is:

http://pietschsoft.com/post/2005/05/VBN ... ntrol.aspx


It's so sweet.[/url]