Valhalla Legends Archive

Programming => General Programming => Visual Basic Programming => Topic started by: Tontow on May 17, 2005, 06:50 PM

Title: Multiple text colors in a single text box?
Post by: Tontow on May 17, 2005, 06:50 PM
Is it possable to add different collored text to a text box? - IE: Have one word be red, the next green, the next blue, etc.
Title: Re: Multiple text colors in a single text box?
Post by: Warrior on May 17, 2005, 06:50 PM
You will have to use a RichTextBox for this.

Edit: More info.

Once you use this control look into the

setColor property.
Title: Re: Multiple text colors in a single text box?
Post by: Newby on May 17, 2005, 06:51 PM
Yes. There was a bug with {\rtfx..} tags that allowed users to specify how big their font was and such.

As long as you're using a rich text box, though.
Title: Re: Multiple text colors in a single text box?
Post by: Warrior on May 17, 2005, 06:52 PM
afaik, theres a message you can send it to render that useless. I forget message
Title: Re: Multiple text colors in a single text box?
Post by: Tontow on May 17, 2005, 09:25 PM
Quote from: Newby on May 17, 2005, 06:51 PM
Yes. There was a bug with {\rtfx..} tags that allowed users to specify how big their font was and such.

As long as you're using a rich text box, though.

Umm, what setColor property, I couldn't find a reference to it on msdn.

And what are {\rtfx..} tags?
Title: Re: Multiple text colors in a single text box?
Post by: Warrior on May 17, 2005, 09:29 PM
The one in the RTB control.
Title: Re: Multiple text colors in a single text box?
Post by: Topaz on May 17, 2005, 09:44 PM
Replacing the slash with the reverse should fix that exploit.
Title: Re: Multiple text colors in a single text box?
Post by: Warrior on May 17, 2005, 09:57 PM
Quote from: Warrior on May 17, 2005, 06:52 PM
afaik, theres a message you can send it to render that useless. I forget message
[/b]

I'll find it later.
Title: Re: Multiple text colors in a single text box?
Post by: Tontow on May 17, 2005, 11:30 PM
I found SelColor, but there is no setcolor that I can see.
Title: Re: Multiple text colors in a single text box?
Post by: Warrior on May 17, 2005, 11:32 PM
Err yea, my bad.
Title: Re: Multiple text colors in a single text box?
Post by: UserLoser. on May 18, 2005, 06:51 AM
Quote from: Newby on May 17, 2005, 06:51 PM
Yes. There was a bug with {\rtfx..} tags that allowed users to specify how big their font was and such.

As long as you're using a rich text box, though.

It's not actually a bug
Title: Re: Multiple text colors in a single text box?
Post by: Ban on May 18, 2005, 10:01 AM
Indeed it is not, its auctually RTF formatting. I'll find a link that has stuff about it later.
Title: Re: Multiple text colors in a single text box?
Post by: UserLoser. on May 18, 2005, 01:50 PM
To simply eliminate this vulnerability to your rich text box, use EM_STREAMIN instead of EM_REPLACESEL (.SelText)
Title: Re: Multiple text colors in a single text box?
Post by: R.a.B.B.i.T on May 18, 2005, 02:00 PM
Or just...don't add it in...
Title: Re: Multiple text colors in a single text box?
Post by: Tontow on May 18, 2005, 08:35 PM
       
        txtmainchat.Text = tempstring(index) & vbCrLf & txtmainchat.Text
        txtmainchat.SelStart = 0
        txtmainchat.SelLength = Len(tempstring(index))
        txtmainchat.SelColor = RGB(163, 163, 163)


tempstring(index) is the text to be added, txtmainchat is the chat window display

It changes all the text that color, when I just want one line that color....

How do I keep this from happing?
Title: Re: Multiple text colors in a single text box?
Post by: Tontow on May 22, 2005, 09:31 PM
Isn't there a more efficient way of color formating a single line of text?

Title: Re: Multiple text colors in a single text box?
Post by: R.a.B.B.i.T on May 22, 2005, 10:25 PM
clicky (http://www.valhallalegends.com/docs/rtbox.htm)
Title: Re: Multiple text colors in a single text box?
Post by: Joe[x86] on May 23, 2005, 04:39 PM
*pretends Rabbit said nothing*

Public Sub AddChat(RTB as RichTextBox, paramArray ColorText as Variant)
    With RTB
        .SelStart = Len(.Text)
        .SelColor = vbWhite
        .SelText = "[" & Time & "] "
        For i = LBound(ColorText) to UBound(ColorText) Step 2
            .SelStart = Len(.Text)
            .SelColor = ColorText(i)
            .SelText = ColorText(i + 1)
        Next i
        .SelStart = Len(.Text)
        .SelText = vbCrLf
        .SelStart = Len(.Text)
    End With
End Sub


An in-depth analysis of AddChat I wrote a while back. (http://www.quikness.com/forums/index.php?showtopic=216) Its a kinda old topic, but as long as you have something on-topic to say, their pretty lax on bumping.

Usage:
Call AddChat(frmMain.rtbChat, vbRed, "This", vbGreen, " is", vbBlue, " colorful!")
[4:38:50] This is colorful!
Title: Re: Multiple text colors in a single text box?
Post by: UserLoser. on May 23, 2005, 04:52 PM
What's the point of setting SelStart so many times?  I only set it (when using the control) at the beginning of function and I've never had any problems..


Public Sub AppendRtb(ByVal Rtb As RichTextBox, ParamArray OutputData() As Variant)
    Dim I As Integer
    With Rtb
        .SelStart = Len(.Text)
        .SelColor = QBColor(ColorWhite)
        .SelText = "[" & Format$(Time$, "hh:mm:ss") & "] "
        For I = 0 To UBound(OutputData) Step 2
            .SelColor = QBColor(CInt(OutputData(I)))
            .SelText = CStr(OutputData(I + 1))
        Next I
    End With
End Sub
Title: Re: Multiple text colors in a single text box?
Post by: Joe[x86] on May 24, 2005, 05:37 PM
Really? Cool. I'm just a paranoid little 8th grader, I suppose.