Valhalla Legends Forums Archive | Visual Basic Programming | Multiple text colors in a single text box?

AuthorMessageTime
Tontow
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.
May 17, 2005, 11:50 PM
Quarantine
You will have to use a RichTextBox for this.

Edit: More info.

Once you use this control look into the

setColor property.
May 17, 2005, 11:50 PM
Newby
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.
May 17, 2005, 11:51 PM
Quarantine
afaik, theres a message you can send it to render that useless. I forget message
May 17, 2005, 11:52 PM
Tontow
[quote author=Newby link=topic=11617.msg112782#msg112782 date=1116373871]
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.
[/quote]

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

And what are {\rtfx..} tags?
May 18, 2005, 2:25 AM
Quarantine
The one in the RTB control.
May 18, 2005, 2:29 AM
Topaz
Replacing the slash with the reverse should fix that exploit.
May 18, 2005, 2:44 AM
Quarantine
[quote author=Warrior link=topic=11617.msg112783#msg112783 date=1116373921]
afaik, theres a message you can send it to render that useless. I forget message
[/quote]


I'll find it later.
May 18, 2005, 2:57 AM
Tontow
I found SelColor, but there is no setcolor that I can see.
May 18, 2005, 4:30 AM
Quarantine
Err yea, my bad.
May 18, 2005, 4:32 AM
UserLoser.
[quote author=Newby link=topic=11617.msg112782#msg112782 date=1116373871]
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.
[/quote]

It's not actually a bug
May 18, 2005, 11:51 AM
Ban
Indeed it is not, its auctually RTF formatting. I'll find a link that has stuff about it later.
May 18, 2005, 3:01 PM
UserLoser.
To simply eliminate this vulnerability to your rich text box, use EM_STREAMIN instead of EM_REPLACESEL (.SelText)
May 18, 2005, 6:50 PM
R.a.B.B.i.T
Or just...don't add it in...
May 18, 2005, 7:00 PM
Tontow
[code]       
        txtmainchat.Text = tempstring(index) & vbCrLf & txtmainchat.Text
        txtmainchat.SelStart = 0
        txtmainchat.SelLength = Len(tempstring(index))
        txtmainchat.SelColor = RGB(163, 163, 163)
[/code]

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?
May 19, 2005, 1:35 AM
Tontow
Isn't there a more efficient way of color formating a single line of text?

May 23, 2005, 2:31 AM
R.a.B.B.i.T
clicky
May 23, 2005, 3:25 AM
JoeTheOdd
*pretends Rabbit said nothing*

[code]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[/code]

An in-depth analysis of AddChat I wrote a while back. 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] [color=red]This[/color] [color=green]is[/color] [color=blue]colorful![/color]
May 23, 2005, 9:39 PM
UserLoser.
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..

[code]
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
[/code]
May 23, 2005, 9:52 PM
JoeTheOdd
Really? Cool. I'm just a paranoid little 8th grader, I suppose.
May 24, 2005, 10:37 PM

Search