?
Solved

... Rich Text Box Changing color of text?

Posted on 1999-11-15
6
Medium Priority
?
246 Views
Last Modified: 2012-05-04
Is there a way to change the color of the text in a rich text box? ...

Rtxt.text = "Hello" & vbCrLf <- in blue
Rtxt.text = Rtxt.text & "Good Bye" & vbCrLf <- in red

?
0
Comment
Question by:ThaSmartUno
  • 3
  • 2
6 Comments
 
LVL 14

Accepted Solution

by:
mcrider earned 200 total points
ID: 2209677
You need to use SelColor.  Here's an example:


With RichTextBox1
    .SelStart = 0
    .SelColor = QBColor(1) ' blue
    .Text = "Hello" & vbCrLf '<- in blue
    iVal = Len(.Text)
    .Text = .Text & "Good Bye" & vbCrLf '<- in red
    .SelStart = iVal
    .SelLength = Len(.Text)
    .SelColor = QBColor(4) ' red
    .SelLength = 0
End With


Cheers!
0
 
LVL 12

Expert Comment

by:mark2150
ID: 2210918
On my web page is a little app (with source) called WHAT2DO. It's a daily calendar. The events for the day have a RTB that you can change colors, fonts, & alignment. Grab a copy and you'll see how it's done.

visit: www.cyberchute.com/rvbus/madmark

M
0
 
LVL 10

Author Comment

by:ThaSmartUno
ID: 2212368
Thanks
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
LVL 10

Author Comment

by:ThaSmartUno
ID: 2212558
well there is one problem ... Im using this is a chatter i have ... and when i change the color it works.  But when I add anything else to the text box it will make it change back to the normal color.... do you know what I could do?
0
 
LVL 14

Expert Comment

by:mcrider
ID: 2212643
Add text to the textbox by using setting the SelStart, SelLength and SelText properties...

For example:


Dim iVal As Long

With RichTextBox1
    .Text = ""
    .SelStart = 0
    .SelLength = 0
    .SelColor = QBColor(1) ' blue
    .SelText = "Hello" & vbCrLf '<- in blue
   
    iVal = Len(.Text)
    .SelStart = iVal
    .SelLength = 0
    .SelText = "Good Bye" & vbCrLf '<- in red
    .SelStart = iVal
    .SelLength = Len(.Text)
    .SelColor = QBColor(4) ' red
    .SelLength = 0
   
   
    iVal = Len(.Text)
    .SelStart = iVal
    .SelLength = 0
    .SelText = "More Text" & vbCrLf '<- in red
    .SelStart = iVal
    .SelLength = Len(.Text)
    .SelColor = QBColor(6) ' red
    .SelLength = 0
   
End With

0
 
LVL 10

Author Comment

by:ThaSmartUno
ID: 2215212
Thank you!  =)

Id give you more points ... but I don't have much to share.  Heh
0

Featured Post

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.

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…
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 process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

593 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