Forum > Graphics

Painting text

(1/3) > >>

Hello coders
I would like to paint text with word wrap like the attached image,
rounded rect, background and border color.

How can I do this on a PaintBox control? Or please give a better idea.
Thanks a lot.

I would create a TBitmap on the fly,
WordWrap I would realize by calculating via "theBitmap.Canvas.TextWidth(AText)"
and to know where the new line starts use "theBitmap.Canvas.TextHeight(AText)"
do not forget to add some space between words, borders, new line etc...
Rounded corners are more challenging due the fact that an image is a 2D rectangle,
anyway you could start experimenting with "theBitmap.Canvas.LineTo()" to draw "from x to y" a line for all borders with a hole/space between.
One thing you should have in mind about the round corners, they are visible as a rectangle (eg background color from bitmap is visible)
When the bitmap is prepared, assign it to the control you need it.


--- Quote from: KodeZwerg on April 11, 2024, 06:46:08 pm ---I would create a TBitmap on the fly...

--- End quote ---

Thanks for the information, but I posted in the forum because I have no idea of how
to paint anything on PaintBox control / canvas. So please, if anybody has a working code
and share with us, I would be so thankful.


Here are some examples:

TextRect can be used to wrap text automatically.

See also developing with graphics for information on graphics and besides that there are plenty enough examples distributed with Lazarus.


[0] Message Index

[#] Next page

Go to full version