RichTextBox mIRC color support

How can I make a RichTextBox control display proper forecolors and backcolors like mIRC does? Also with Bold/Underline/Reverse
for example
|12,3This is a |15test
(replace | with the color bar)

It would be useful to have a sub like this: IRCColor(byval strText As String, byval RichText As RichTextBox)

Any assistance would be appreciated.
garlic2Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

appariCommented:
you can use selcolor, selbold, selitalic etc... methods to change colors and font styles.
some thing like this

Private Sub Command1_Click()
RichTextBox1.SelColor = vbRed
RichTextBox1.SelBold = True
End Sub

the above sub changes currently selected text in richtextbox color to red and make bold.

0
appariCommented:

to select particular part of text in richtextbox from program itself, set selstart and sellength properties.

example:
Private Sub Command1_Click()
RichTextBox1.SelStart = 3
RichTextBox1.SelLength = 3
RichTextBox1.SelColor = vbRed
RichTextBox1.SelBold = True
End Sub

the above sample sets 3 chars from 3rd character, color to red and make bold
0
KarcOriginCommented:
Try this-

Option Explicit

Private Sub Command1_Click()
    Call IRCColor("is", RichTextBox1)
End Sub

Private Sub Form_Load()
    RichTextBox1.Text = "Hi my name is Karc Origin" & vbNewLine & "What is your name?!" & vbNewLine & "Is it what you want?"
End Sub

Private Sub IRCColor(ByVal strText As String, ByVal RichText As RichTextBox)
    With RichText
       
        ' Setting the default formatting values
        .SelStart = 0
        .SelLength = Len(.Text)
        .SelColor = vbBlack
        .SelUnderline = False
       
   
        Dim st As Long
        st = 0
       
        ' This loop will go through the text in the richtext box and will make it underline and red
        ' NOTE: You can choose other format options too; like .SelBold, .SelUnderline and others
        Do While (.Find(strText, st) >= 0)
            st = .Find(strText)
            ' Set the Start and Length before setting any formatting options
            .SelStart = st
            .SelLength = Len(strText)
           
            .SelUnderline = True
            .SelColor = vbRed
            ' Incrementing the pointer in the richtextbox
            st = st + 1
        Loop
       
    End With

End Sub

I hope this will give you an idea that you want to achive.
Cheers!

0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

List244Commented:
Just a little help:

Chr(3) is going to specify a color change from mIRC
Chr(2) will be bold
Chr(22) Highlight (or reverse)
Chr(31) is going to specify Underline

0
garlic2Author Commented:
thanks for your comments, but it's not exactly what I'm looking for.

The formatting is not a problem, setting colors and backcolors is not a problem either. The main prob is knowing where to start, and knowing where to end the formats. It's very much like html, like with bolding <b>text </b>

This time, it's with IRC formatting codes. Like this:
|1,13 <- forecolor is 1, backcolor is 13
So we might have something like this:

"|1,13This is text |3,11on the same line"

the first part has different colors than the second. Also, there's format codes for bold,underline,reverse as well, which are only one character

for example, for bolding, the | character isn't the actual marker, but it's for an example.
"|this is bolded |here it's not"

There are 15 colors that mIRC supports, and the different formats are: bold,underline,reverse
I hope this helps clarifies what is needed for writing a procedure that does this.

0
HoweverCommaCommented:
You have all the info you need to know here, just need to piece it all together.
You are going to have to build a Parsing function that will handle the strings and set things for you dynamically.

Search for chr(3) in a string if found replace it with "" then write the text up to that point to the RTB.
Then parse the color/format info from it, and remove those numbers.
Thisd link give info on how to insert the text as RTF text the settings you parse will be needed to pass to these functions
to insert the text into the RTB.
http://www.codeproject.com/cs/miscctrl/csexrichtextbox.asp

And a little boost to get you started on your function

Sub ParseCodes (CodeText As String)

' Check for Color Code change
If Instr(CodeText,Chr(3))
'Extract the format codes in here and save them to variables for later use
'You can use thew Instr function to get the position of the Chr(3) value add 1 to it and you will be at the first number.
The position of the Comma -1 will be the end of the number use these two values with the mid function to extract them.
End if
Repeat the same for Chr(3),Chr(22) and Chr(31)

and call the insert funtion from the link above using the values parsed from the string as the parameters.




0
garlic2Author Commented:
Thanks for the tips.

This has already been done.
The only things which are remaining are Reverse and Normal text chr(15) support and a couple of flaws I can't seem to fix.

Please see this procedure I'm writing, the flaws are listed on the form itself.
http://www.parsimage.com/irccolors.zip
0
garlic2Author Commented:
None of the answers were complete, I would like to ask for a refund.
0
List244Commented:
according to : >>The formatting is not a problem, setting colors and backcolors is not a problem either. The main prob is knowing where to start, and knowing where to end the formats. It's very much like html, like with bolding <b>text </b>

I am sorry that we have failed to answer your question. It appeared answered to me.
I have gone through, and it seems you say the problem is knowing how to apply changes,
correct? I have written for you an example on how you would go about this:

Public Sub DrawText(FontTC As String, AddTo As RichTextBox)
Dim TFont As IRCFont, FText As String, Nbox As RichTextBox, I As Long
FText = FontTC
TFont.FColor = vbBlack
TFont.FBold = False
TFont.FUnderline = False
For I = 1 To Len(FText)
    Select Case Mid(FText, I, 1)
        Case Chr(3)
            If Mid(FText, I + 1, 2) = 15 Then
                TFont.FColor = RGB(200, 200, 20)
                I = I + 2
            End If
            If Mid(FText, I + 1, 2) = 14 Then
                TFont.FColor = RGB(100, 100, 100)
                I = I + 2
            End If
            If Mid(FText, I + 1, 2) = 13 Then
                TFont.FColor = RGB(255, 0, 255)
                I = I + 2
            End If
            If Mid(FText, I + 1, 2) = 12 Then
                TFont.FColor = RGB(0, 0, 255)
                I = I + 2
            End If
            If Mid(FText, I + 1, 2) = 11 Then
                TFont.FColor = RGB(0, 255, 255)
                I = I + 2
            End If
            If Mid(FText, I + 1, 2) = 10 Then
                TFont.FColor = RGB(0, 128, 128)
                I = I + 2
            End If
            If Mid(FText, I + 1, 1) = 0 Then
                TFont.FColor = RGB(255, 255, 255)
                I = I + 1
            End If
            If Mid(FText, I + 1, 1) = 1 Then
                TFont.FColor = RGB(0, 0, 0)
                I = I + 1
            End If
            If Mid(FText, I + 1, 1) = 2 Then
                TFont.FColor = RGB(0, 0, 128)
                I = I + 1
            End If
            If Mid(FText, I + 1, 1) = 3 Then
                TFont.FColor = RGB(0, 0, 128)
                I = I + 1
            End If
            If Mid(FText, I + 1, 1) = 4 Then
                TFont.FColor = RGB(255, 0, 0)
                I = I + 1
            End If
            If Mid(FText, I + 1, 1) = 5 Then
                TFont.FColor = RGB(128, 0, 0)
                I = I + 1
            End If
            If Mid(FText, I + 1, 1) = 6 Then
                TFont.FColor = RGB(128, 0, 128)
                I = I + 1
            End If
            If Mid(FText, I + 1, 1) = 7 Then
                TFont.FColor = RGB(255, 128, 64)
                I = I + 1
            End If
            If Mid(FText, I + 1, 1) = 8 Then
                TFont.FColor = RGB(255, 255, 0)
                I = I + 1
            End If
            If Mid(FText, I + 1, 1) = 9 Then
                TFont.FColor = RGB(0, 255, 0)
                I = I + 1
            End If
        Case Chr(31)
            If TFont.FUnderline = True Then TFont.FUnderline = False Else TFont.FUnderline = True
        Case Else
            AddTo.SelStart = Len(AddTo)
            AddTo.SelLength = 1
            AddTo.SelColor = TFont.FColor
            AddTo.SelBold = TFont.FBold
            AddTo.SelUnderline = TFont.FUnderline
            AddTo.SelText = Mid(FText, I, 1)
    End Select
Next I
End Sub

However, it does not do ALL of the features you need, it should be enough to show you HOW to do them.
That should be good. Now, let me explain the function to you:

FontTC is going to be the string that holds the mIRC codes that need added to AddTo.
Then
AddTo is where to add FontTC (with formatting) to.

This should solve your problem with managing the parsing. Each color has been set for you in accordance to
mIRC's colors. Also, Bold and such, can be added by copying the underline function, and altering it to your
needs.

Good luck to you, sorry for the late response, I was under the impression you had the problem solved.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
List244Commented:
Glad I could be of some help, let me know if that brings up any further issues.
If it is relating to that, I will do my best to help out.
0
garlic2Author Commented:
your assistance is appreciated
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.