Inserting Text to the beginning of a RichTextBox maintaining colors

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

  • 4 months 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.

“I invented the term Object-Oriented, and I can tell you I did not have C++ in mind.” - Alan Kay