Link to home
Start Free TrialLog in
Avatar of garlic2
garlic2

asked on

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.
Avatar of appari
appari
Flag of India image

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.


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
Avatar of KarcOrigin
KarcOrigin

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!

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

Avatar of garlic2

ASKER

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.

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.




Avatar of garlic2

ASKER

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
Avatar of garlic2

ASKER

None of the answers were complete, I would like to ask for a refund.
ASKER CERTIFIED SOLUTION
Avatar of List244
List244

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.
Avatar of garlic2

ASKER

your assistance is appreciated