2017-02-01 5 views
3

このテキストボックスは、実際にはゲームチャットです。ユーザー名:メッセージVB6 Rich TextBoxのcreatin text partの色の書式設定

私がここでやりたいことは、何らかの理由でUserNameテキストが常に異なる色で表示されるようにするためです。実際のメッセージから少し離れています。

ここで私は現在、使用していたコードです:

AddChatMsg 0, userName & ": " & theMsg 'send it to the chatbox 

Dim curColor As Long 'current text color 
Dim userNameLength As Integer 'username length 

userNameLength = Len(UserName) 'store username in integer var 
With MyForm.ChatText 
    curColor = .SelColor 'set curColor 
    .SelLength = userNameLength 'set Length 
    .SelColor = vbRed 'change color 
    .SelText = UserName 'not sure wha this do 
    .SelColor = curColor 'update current color var 
End With 

をこれが実際にうまく動作しますが、ユーザ名は唯一の最初のテキスト行の赤です:

Image of Chat

どのように私はそれを作るのですが、すべての行に対応していますか?また、可能であればフォントを太字に変えることは素晴らしいでしょう。ありがとうございました!

答えて

1

ユーザー名とメッセージを分けて保存してから、色を設定して個別に書き込んでください(例:使用

AddChatMsg "DonaldTrump", "I like to grab em" 

:動作しません

Sub AddChatMsg(UserName As String, theMsg As String) 
    Dim curColor As Long 'current text color 
    With MyForm.ChatText 
     curColor = .SelColor 
     .SelStart = Len(.Text) 'ensure we are at the end 
     .SelColor = vbRed 
     .SelBold = True 'write in bold 
     .SelText = UserName 
     .SelBold = False 
     .SelColor = curColor 
     .SelText = ": " & theMsg & vbCrLf 
    End With 
End Sub 
+0

をとして呼び出します。チャットボックス全体が乱雑になり、送信されたテキストは全く表示されず、チャットボックスに表示されるのは4です:4は赤と太字で:は普通の黒です。 – zeroClarity

+0

それは私のためにうまく動作します、それはあなたがそれを渡す場合4を表示します4 –

+0

私のコードは使用されていないように私のコードはあなたの例では 'AddChatMsg 0、' 'に' 0'を含めないでください2弦のみ。 –