Solved

Richedit colors

Posted on 1998-06-19
4
244 Views
Last Modified: 2013-11-22
Hi i want to be able to insert text lines into a richeditbox from my code, the special thing: i want to put colors in it. with some kind of color codes.

eg: me.editbox.addline "@RED@this is red@BLUE@this is blue"

Can anyone help me ?

Best regards,
Arijan
0
Comment
Question by:aluiken
  • 2
4 Comments
 
LVL 1

Expert Comment

by:wford
ID: 1463763
You could use seltext and selcolor and selstart like so,

With RichTextBox1
    .Text = "First line in standard" & Chr(10)
    'get insert position
    .SelStart = Len(.Text)
    'set the new color
    .SelColor = vbRed
    'insert the line
    .SelText = "new line in red" & Chr(10)
    'find the end of 1st line
     .SelStart = Len(.Text)
    .SelColor = vbBlack
    .seltext = "I'm back to black"
End With

This can be a little limiting, but is quick and easy,Or you could edit the RTF code itself to insert a line in red, but this is not as simple as the method above. If you would rather the RTF answer, reject the one above and i'll dig out that that code.
0
 
LVL 1

Author Comment

by:aluiken
ID: 1463764
Hi, yes i think that the rtf sollution would be much faster and stable, if you dig out the code could you also think about the other color tags for me ? that is the problem where i am stuck at. (my own color codes @RED@ or somthing line that), Because i want to write a sub that adds a line to an richedit.

Thx !
0
 
LVL 18

Accepted Solution

by:
deighton earned 100 total points
ID: 1463765
EXAMPLE CALL

Private Sub Command1_Click()
    Dim sfStr As String
   
    sfStr = "@GREEN@Argentina@RED@England@GREEN@Brazil"
   
    Call AddText(RichTextBox1, sfStr)
   
End Sub


Sub I have written - I had a lot of problems getting things to work!

Sub AddText(rtb As RichTextBox, sfStr As String)

    'Fills a text box with coloured text

    Dim c As Integer
    Dim idColor As Long
    Dim sColor As String
    Dim a(500) As Long
    Dim i As Integer
   
    idColor = vbBlack
   
    rtb.SetFocus
   
    c = 1
    Do Until c > Len(sfStr)
       
        'Get the color code
        If Mid(sfStr, c, 1) = "@" Then
           
           
            c = c + 1
            sColor = ""
           
            Do Until c > Len(sfStr) Or Mid(sfStr, c, 1) = "@"
           
                sColor = sColor + Mid(sfStr, c, 1)
                c = c + 1
           
            Loop
           
            'Add all your colors here with their codes by adding more if statements
            'You might want to use CASE statement here
             
            If sColor = "RED" Then
                idColor = vbRed
            ElseIf sColor = "BLUE" Then
                idColor = vbBlue
            ElseIf sColor = "GREEN" Then
                idColor = vbGreen
            End If
           
        Else
       
            rtb.Text = rtb.Text + Mid(sfStr, c, 1)
            i = i + 1
            a(i) = idColor

           
        End If

       
        c = c + 1
       
    Loop
   
   
    'Set the colors - This is the only way I couold find that actually worked
    For c = 1 To i
        rtb.SelStart = (c - 1)
        rtb.SelLength = 1
        rtb.SelColor = a(c)
    Next
   
End Sub



0
 
LVL 1

Author Comment

by:aluiken
ID: 1463766
Perfect THX !
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Validating VB6 Function 19 50
I need help formating a date variable in my VB.Net application 2 35
VBA filters 2 39
Copy a row 12 53
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

743 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now