Inserting Text to the beginning of a RichTextBox maintaining colors

VB.Net , RichTextBox , .Net Thousand Oaks, United States
  • 3 years ago

    I have the following code:

    txtStatusLog.SelectionStart = 0
    txtStatusLog.SelectionLength = 0
    txtStatusLog.SelectedText = ("ERROR: " & MyUpdate & "(" & Now & ")" & vbCrLf)
    txtStatusLog.SelectionColor = Color.Red
    

    Only problem is that when a different color is selected, the color either never appears or changes the entire text box that color. Any ideas on how to correct this?

  • 3 years ago

    Looks like it works if I change the order a bit:

        txtStatusLog.SelectionStart = 0
        txtStatusLog.SelectionLength = 0
        txtStatusLog.SelectionColor = Color.Red
        txtStatusLog.SelectedText = ("ERROR: " & MyUpdate & "(" & Now & ")" & vbCrLf)
    

Post a reply

Enter your message below

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Brevity is the soul of wit” - Shakespeare