?
Solved

Color Problem with Rich Text Box vb6

Posted on 2009-06-29
4
Medium Priority
?
483 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 500 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

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

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

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…
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…
Suggested Courses

800 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