1. Computing
How To Create a Word Wrapped TButton

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:
  1. Start Delphi and select File | New Application...
  2. Put a TButton on your form.
  3. In the Object Inspector, empty the Caption property.
  4. Place a TLabel anywhere on the form
  5. In the Object Inspector, set the Caption property (of a Lablel) as you like (the long one).
  6. Also, set the WordWrap property to True.
  7. 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
    ...

  8. Move the TLabel declaration into the TButton declaration,
  9. Change the coordinates since it is now relative to the button.
  10. 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
    ...

  11. Display the form as form.
  12. That's it.
Tips:
  1. 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:

©2014 About.com. All rights reserved.