Reputation: 155
I am using a Rich Text Box as a display log for my program. The program preforms a mass copy of one directory from a source machine to multiple target machines. I wish to bold the computer name as added to the the text box as I add the lines. I currently add the lines as follows:
rtbStatusLog.AppendText(My.Computer.Clock.LocalTime.ToString + " " + TargetName + ": File Copied: " + destinationFileName + vbCrLf)
I need the "Target Name" variable, and subsequent: to be bold, but nothing else.
I also wish to do this as the lines are added if possible instead of selecting the results at the end and bolding them.
Upvotes: 0
Views: 1282
Reputation: 3635
A rich text box has a property called SelectionFont
. Setting attributes of this property changes the way the text is shown.
So do it like this:
Dim currentFont As System.Drawing.Font = rtbStatusLog.SelectionFont
Dim newFontStyle As System.Drawing.FontStyle
rtbStatusLog.SelectedText = My.Computer.Clock.LocalTime.ToString
rtbStatusLog.SelectionFont = New Font(currentFont.FontFamily,currentFont.Size,newFontStyle)
rtbStatusLog.SelectedText = " " + TargetName + ": File Copied: " + destinationFileName + vbCrLf)
When you change the SelectedText
property you are actually writing to the box.
Upvotes: 0