I would like to draw into a Canvas several lines of text.
Each line is composed by 3 parts of text, with different font colors.
And I would like to prepare the full text in a method, for then drawing it all together at once into the Canvas.
I would you approach this?
I tried to use “TextShape” but it seems you cannot combine different TextShapes into one …
Thanks a lot !
PS: I know that I could use a text area, but it is not what I need.
Thanks time. Indeed I read that already.
But how can I combine different “text styles” in the same line, and combine multiple text lines?
And if possible “build” the text in a subroutine and then send it to the pain event of canvas …
Thanks again !
You have to do all the actual writing in the Paint event in one go. You would have to create a structure describing your text and the text itself and then fire the Paint event which would decode your structure and draw the text. That seems a lot of work.
In my case I used a DesktopTextArea, enabled Styled Text, and used StyleRuns. Still quite a bit of work and made more complex for me because I wanted two columns, meaning I couldn’t use the TextArea’s scrollbar and had to account for the height of all the text, as well as manage a scrollbar too.
thanks a lot for the suggestions and for sharing interesting code.
At the end, I opted for making a 2-dimensional array of TextShape, where each row represent a paragraph, and it is composed by 3 columns which contain the 3 text parts of styled text.
Then in the paint event I just load any information contained in this 2-dimensional array.
It seems to work, (I also realised that I dont need the canvas, I can directly use the paint event of the window), but I jut need to be sure if it is energy (=CPU) efficient.
Thanks again to all.
Luciano