Inserting Text to the beginning of a RichTextBox maintaining colors

VB.Net , RichTextBox , .Net Thousand Oaks, United States
  • 1 month 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?

  • 1 month 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.

“Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.” - Brian Kernighan