Richtextbox Color Syntax Help(VB)

Post here about scripting and programming for HaloPC (audio, network, ai, etc.)
Post Reply
jebtrillion





Posts: 45
Joined: Tue Jun 12, 2007 2:07 pm

Richtextbox Color Syntax Help(VB)

Post 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
User avatar
xzodia




Translator Connoisseur Coagulator

Posts: 1981
Joined: Sun May 15, 2005 10:31 am
Location: UK
Contact:

Post 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
Image
Halo 2 Plugins | Lock-on To Just About Anything | My Sites | Snow Hog
Old Plugins you have, upgrade you must...
Always Maintain a High Quality-To-Crap Ratio.
Patrickssj6




Pi Collaborator

Posts: 5426
Joined: Sat Jul 24, 2004 12:12 pm
Location: I'm a Paranoid
Contact:

Post by Patrickssj6 »

Same here
...left for good
User avatar
bcnipod





Posts: 3580
Joined: Tue May 15, 2007 8:52 am
Location: 45 Minutes outside Boston
Contact:

Post by bcnipod »

I know how to do it in Cocoa, but not VB
Twitter: Dirk Gently | Major lulz
Mr. Brightside: Worst mod I've seen since 'Nam.
Website
User avatar
Prey




Connoisseur Snitch! Pyre Articulatist 500

Posts: 1026
Joined: Wed Dec 27, 2006 6:49 am
Location: UK
Contact:

Post 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.
Halo 2 Prophet - Skin with ease with the simple 3D point and click interface.
Halo 3 Research Thread - Contribute to the research into Halo 3.
jebtrillion





Posts: 45
Joined: Tue Jun 12, 2007 2:07 pm

Post 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]
Post Reply