• Welcome to Valhalla Legends Archive.
 

Multiple text colors in a single text box?

Started by Tontow, May 17, 2005, 06:50 PM

Previous topic - Next topic

Tontow

Isn't there a more efficient way of color formating a single line of text?



Joe[x86]

#17
*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. 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!
Quote from: brew on April 25, 2007, 07:33 PM
that made me feel like a total idiot. this entire thing was useless.

UserLoser.

#18
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

Joe[x86]

Really? Cool. I'm just a paranoid little 8th grader, I suppose.
Quote from: brew on April 25, 2007, 07:33 PM
that made me feel like a total idiot. this entire thing was useless.