I have a textarea in which my app writes logging messages. I’d like to be able to colour the odd message in a highlight colour. Playing around with styled text, I can write a line of red text but only the most recent message gets the highlight. My logging method is:
Sub logger (strtext as String, colour as Color)
Var len As Integer
// logst is a StyledText property of the window
len = logst.Text.Length
logst.Text = logst.Text + strtext + EndOfLine
logst.TextColor (len, strtext.Length) = colour
TextArea1.StyledText = logst
end sub
It looks like modifying the text content of the StyledText removes all existing style information. Is there a real way to do this?
Untested, but you could work directly on the textarea itself.
TextArea1.SelectionStart = TextArea1.Text.Length // selection is at end of text
TextArea1.SelectedText = strtext + EndOfLine
TextArea1.SelectionTextColor = colour
TextArea1.SelectionTextColor = colour
TextArea1.SelectionStart = TextArea1.Text.Length // selection is at end of text
TextArea1.SelectionLength = strtext.Length
TextArea1.AddText (strtext + EndOfLine)