Struggling with text styles

I want to add a line of text to a TextArea. The area already has text in it. I want to color that new specific line blue and not the rest of the Textarea.

How to do that?

Check the documentation sample-code: StyledText — Xojo documentation

Of course. Done that. Ran the demo code. But it doesn’t show you to change one single line.

DesktopTextArea.SelectionTextColor = Color.Blue
DesktopTextArea.AddText("The blue line text" + EndOfLine)
DesktopTextArea.SelectionTextColor = Color.Black

That is a bit simplistic. You need style runs and then you add the style run to the styled text.

Did the trick…

No, it works for my purpose

1 Like

If you are going to work with more than just a few pages of styled text… i would highly recommend to not use the RTF styling in a Xojo TextArea control… way… too… slow. There are multiple alternatives available.

Could you please tell, which they are (not MBS)?

Sharing this with you, we wrote this control for our main application (the control within the green square)

  • Supports key binding, in the demo you can use CTRL+1,2,3,4,5,6 to easily switch font styles.
  • Supports two types of toolbars, traditional and a popup (visible when text is selected).
  • You can define most properties in the IDE and the font styling you set, will also affect the clipboard behaviour when user pastes content into the editor, so you do not need to process the incoming data.
  • Supports mentions, in the demo the user has defined # $ % & { [ as a mention trigger.
  • You can get the content of the editor as text, html, xml, json etc.
  • Lightning fast, wether a paragraph of plain text or hundreds of pages of styled text.
  • Use the Opening event to set properties / define behaviour before the class is initialised, use the EditorReady event to make any additional changes after initialisation but before the document is loaded.
  • Single class, no external files.
  • No 3rd party plugins.
  • Mac and Win compatible
2 Likes