Mirror

Word wrapped TButton (Views: 100)


Problem/Question/Abstract:

Word wrapped TButton

Answer:

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.
Of course, you could search the web for some third-party component, but there's an easier way to accomplish this. Just follow these steps:

Put a TButton with empty caption on your form;

Create a TLabel with your desired caption and place it anywhere on the form;

Display the form as text (Alt+F12) and it will look as on the left side in the table;

Move the TLabel declaration into the TButton and change the coordinates since it is now relative to the button;

(idea from Richard B. Winston:) 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.

(before step 4)
(after step 4)
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 caption'
  WordWrap = True
end
object Button1: TButton
  Left = 176
  Top = 184
  Width = 75
  Height = 25
  Caption = ''
  TabOrder = 2
  object Label1: TLabel
    Left = 2
    Top = 2
    Width = 32
    Height = 13
    Caption = 'My long caption'
    WordWrap = True
  end
end

<< Back to main page