Solved

Color Problem with Rich Text Box vb6

Posted on 2009-06-29
4
482 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 86

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 86

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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

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…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…

687 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