[Webinar] Streamline your web hosting managementRegister Today

x
?
Solved

RichTextBox mIRC color support

Posted on 2004-10-23
12
Medium Priority
?
488 Views
Last Modified: 2013-12-26
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.
0
Comment
Question by:garlic2
  • 4
  • 3
  • 2
  • +2
11 Comments
 
LVL 39

Expert Comment

by:appari
ID: 12398194
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
 
LVL 39

Expert Comment

by:appari
ID: 12398204

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
 
LVL 5

Expert Comment

by:KarcOrigin
ID: 12398758
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
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
LVL 8

Expert Comment

by:List244
ID: 12401681
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
 

Author Comment

by:garlic2
ID: 12401749
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
 
LVL 7

Expert Comment

by:HoweverComma
ID: 12405828
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
 

Author Comment

by:garlic2
ID: 12406594
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
 

Author Comment

by:garlic2
ID: 12815029
None of the answers were complete, I would like to ask for a refund.
0
 
LVL 8

Accepted Solution

by:
List244 earned 2000 total points
ID: 12815830
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
 
LVL 8

Expert Comment

by:List244
ID: 12816204
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
 

Author Comment

by:garlic2
ID: 12819164
your assistance is appreciated
0

Featured Post

Take Control of Web Hosting For Your Clients

As a web developer or IT admin, successfully managing multiple client accounts can be challenging. In this webinar we will look at the tools provided by Media Temple and Plesk to make managing your clients’ hosting easier.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month7 days, 13 hours left to enroll

607 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question