Forum > Graphics

Painting text

(1/3) > >>

SaraT:
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.

KodeZwerg:
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.

SaraT:

--- 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.

Regards!

paweld:
Here are some examples: https://lazplanet.gitlab.io/2013/06/how-to-draw-text-on-canvas.html

TRon:
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.

Navigation

[0] Message Index

[#] Next page

Go to full version