Solved

Color Problem with Rich Text Box vb6

Posted on 2009-06-29
4
477 Views
Last Modified: 2013-12-26
Hello, I am working on a messenger which has some chat rooms now the problem is when someone enters/leave a room it show in blue that user has entered/left but after a while when someone else enter/leave all the old textformatting comes to defualt (black) here is my code:


Public Sub AddStatusMessage(RTB As Object, _
    ByVal Color As Long, Message As String)
    If Not TypeOf RTB Is RichTextBox Then Exit Sub
   
    With RTB
        .SelStart = Len(.Text)
        .SelFontName = "Tahoma"
        .SelFontSize = 9
        .SelBold = False
        .SelItalic = False
        .SelUnderline = False
        .SelColor = Color
        .SelText = Message & vbCrLf
    End With
End Sub

IT works quite fine but how to remain other colors
0
Comment
Question by:BILAL69
  • 2
  • 2
4 Comments
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 24738611
The code you have posted looks fine.

The symptom of losing all previous formatting and everything going to black is usually caused by setting the Text() property:

    RTB.Text = RTB.Text & "new message" & vbCrLf ' <---- this is wrong way to go about it

Do you have any other code that deals with the RichTextBox?...and if so, does it directly assign the Text() Property like above?
0
 
LVL 2

Author Comment

by:BILAL69
ID: 24738681
well i only use this code when someone enter/leave so.. when its not i just say txtChat.text = txtChat.text & themsg & vbcrlf

also how do i know the color in RGB() ? like if i want the pink color :-/
0
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 125 total points
ID: 24738759
Therein lies the problem:

    txtChat.text = txtChat.text & themsg & vbcrlf

That will ERASE the previous formatting in the RTB.  You need to use code just like in your AddStatusMessage() method if you want to add something to the end without destroying all of your formatting.  =)

To pick your own color, use the RGB() function:
http://msdn.microsoft.com/en-us/library/zc1dyw8b(VS.80).aspx

So it would be something like:

    Dim myColor As Long
    myColor = RGB(255, 192, 203)
0
 
LVL 2

Author Comment

by:BILAL69
ID: 24738908
oh correct thnx :D
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
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…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

758 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

19 Experts available now in Live!

Get 1:1 Help Now