Solved

Color Problem with Rich Text Box vb6

Posted on 2009-06-29
4
479 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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…
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…

785 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