If you want to have your TButton objects displayed with wrapped caption, you will notice that this is not possible - not possible without a little trick...
Difficulty Level: easy Time Required: 5 minutes
Here's How:
- Start Delphi and select File | New Application...
- Put a TButton on your form.
- In the Object Inspector, empty the Caption property.
- Place a TLabel anywhere on the form
- In the Object Inspector, set the Caption property (of a Lablel) as you like (the long one).
- Also, set the WordWrap property to True.
- Display the form as text (Alt+F12) and it will look like:
object Button1: TButton
Left = 176
Top = 184
Width = 75
Height = 25
Caption = ''
TabOrder = 2
end
object Label1: TLabel
Left = 200
Top = 168
Width = 32
Height = 13
Caption = 'My long-long caption'
WordWrap = True
end
... - Move the TLabel declaration into the TButton declaration,
- Change the coordinates since it is now relative to the button.
- It should now look like:
...
object Button1: TButton
Left = 176
Top = 184
Width = 75
Height = 25
Caption = ''
TabOrder = 2
object Label1: TLabel
Left = 200
Top = 168
Width = 32
Height = 13
Caption = 'My long-long caption'
WordWrap = True
end
end
... - Display the form as form.
- That's it.
- Select the button and then "Component|Create Component Template".
After you choose a name and palette page for the template,
you will be able to select the button with embedded label from
the component palette and use it just like any other component.
Related Features:
- Working With Components
- How To Create a TButton at Run-Time
- How To Create Component Templates in Delphi
- More Delphi Programming HOW TOs

