Textbox code to make certain things bold and different color

Lanc1988

Contributor
Joined
Nov 27, 2003
Messages
508
I have a chat project and i am using a multi line textbox to show what everyone is saying but I would like to be able to bold the usernames and also make them a different color.. so basically, what is the code to format certain text in a textbox to bold and different colors.

Example:
Visual Basic:
Txtarrive.Text = String.Concat(Txtarrive.Text, vbNewLine & "<" & Nickname & "> " & txtSend.Text)
I need the 'Nickname' part of that line to be in bold and a different color.. like blue or something.
 
ok, i replaced it with a rich textbox.. but im not sure how to get just the Nickname part in bold and a different color.. here is the code for bold: New Font("Arial", 12, FontStyle.Bold)

I just need to get only Nickname bold, not the whole richtextbox.
 
Lanc1988 said:
ok, i replaced it with a rich textbox.. but im not sure how to get just the Nickname part in bold and a different color.. here is the code for bold: New Font("Arial", 12, FontStyle.Bold)

I just need to get only Nickname bold, not the whole richtextbox.

I haven't used this control in .NET but I would venture a guess and say something like this:
Code:
//set the bold for the username
New Font("Arial",12,FontStyle.Bold);
Text1.text +="\r\n" + strUserName; 
//set to normal for teh rest of the text
New Font("Arial",12,FontStyle.Regular);
Text1.text +=": " + strMessage;
 
Find NickName in the textbox, and highlight it (you can do this with IndexOf, RTB.SelectionStart and RTB.SelectionLength

From here, you set the RTB.SelectedFont to a New Font("Arial", 12, FontStyle.Bold) :)
 
ok, i added this and it isn't working:
Visual Basic:
        textMessages.SelectionStart = textNick.Text
        textMessages.SelectionLength = textNick.Text
        textMessages.SelectionFont = New Font("Tahoma", 9, FontStyle.Bold)
 
You need to use IndexOf to find the location of the textNick.Text. SelectionStart and selectionlength are integers... you should not assign strings to them.
:)
 
Back
Top