* * *

Author Topic: How i insert text in a TShape?  (Read 495 times)

celso.lom

  • Newbie
  • Posts: 3
How i insert text in a TShape?
« on: February 02, 2012, 05:14:01 pm »
I created a TShape in runtime and i need to insert text in. How i do this?

felipemdc

  • Administrator
  • Hero Member
  • *
  • Posts: 3162
Re: How i insert text in a TShape?
« Reply #1 on: February 02, 2012, 05:32:37 pm »
Create a TCustomControl descendent and in its Paint method you can draw your shape using TCanvas routines and also draw the text:

http://wiki.lazarus.freepascal.org/Developing_with_Graphics#Create_a_custom_control_which_draws_itself

See also:

http://lazarus-ccr.sourceforge.net/docs/lcl/graphics/tcanvas.html

typo

  • Hero Member
  • *****
  • Posts: 1368
Re: How i insert text in a TShape?
« Reply #2 on: February 02, 2012, 05:42:23 pm »
Code: [Select]
YourShape.Canvas.TextOut(0,0,'abc');

felipemdc

  • Administrator
  • Hero Member
  • *
  • Posts: 3162
Re: How i insert text in a TShape?
« Reply #3 on: February 02, 2012, 06:35:40 pm »
Code: [Select]
YourShape.Canvas.TextOut(0,0,'abc');

Indeed that might work, but should only be used inside the OnPaint event of the shape.

celso.lom

  • Newbie
  • Posts: 3
Re: How i insert text in a TShape?
« Reply #4 on: February 02, 2012, 06:36:38 pm »
I tested the "TShape.Canvas.TextOut." By moving the TShape the text disappears. I create the TShape at runtime, and I would definitely put the text inside. Is there another way?
Translated from portuguese on Google Translator.

typo

  • Hero Member
  • *****
  • Posts: 1368
Re: How i insert text in a TShape?
« Reply #5 on: February 02, 2012, 06:52:33 pm »
Test what Felipe said.

celso.lom

  • Newbie
  • Posts: 3
Re: How i insert text in a TShape?
« Reply #6 on: February 02, 2012, 07:08:00 pm »
I tested what Felipe said and it worked. As I am creating buttons dynamically, the procedures have to be dynamic. Added value to TShape.Caption and recovered within the procedure. Thanks!
Translated from portuguese on Google Translator.

 

Recent

Get Lazarus at SourceForge.net. Fast, secure and Free Open Source software downloads