Examples Delphi

Question:
How do I get linebreak on a button's caption?
Answer 1:
You could use a SpeedButton or a BitButton instead of TButton. The disadvantage is that they are not native Windows components, thus overhead, different inheritance, other (window) messages e.g. the TSpeedButton cannot receive the focus.
Better solution -> Answer 2:
Answer 2:
Make a TButton descendent that has the BS_MULTILINE button style. Below is such a class which allows you to use the pipe character ('|') as a substitute for #13 in the designer when setting the button's caption.

unit MLButton;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TMultilineButton = class(Tbutton)
private
FMultiline: Boolean;
function GetCaption : String;
procedure SetCaption(const Value: String);
procedure SetMultiline(const Value: Boolean);
public
procedure CreateParams(var params: TCreateParams); override;
constructor Create(aOwner: TComponent); override;
published
property Multiline : Boolean read FMultiline write SetMultiline default True;
property Caption : String read GetCaption write SetCaption;
end;
procedure register;
implementation
procedure register;
begin { register }
RegisterComponents('Samples', [TMultilineButton]);
end; { register }
{ TMultilineButton }
constructor TMultilineButton.Create(aOwner: TComponent);
begin { TMultilineButton.Create }
inherited;
FMultiline := True;
end; { TMultilineButton.Create }
procedure TMultilineButton.CreateParams(var params: TCreateParams);
begin { TMultilineButton.CreateParams }
inherited;
if FMultiline then
begin
params.Style := params.Style or BS_MULTILINE
end;
end; { TMultilineButton.CreateParams }
function TMultilineButton.GetCaption : String;
begin { TMultilineButton.GetCaption }
Result := Stringreplace(inherited Caption, #13, '|', [rfReplaceAll]);
end; { TMultilineButton.GetCaption }
procedure TMultilineButton.SetCaption(const Value: String);
begin { TMultilineButton.SetCaption }
if Value<>Caption then
begin
inherited Caption := Stringreplace(Value, '|', #13, [rfReplaceAll]);
Invalidate;
end { Value<>Caption };
end; { TMultilineButton.SetCaption }
procedure TMultilineButton.SetMultiline(const Value: Boolean);
begin { TMultilineButton.SetMultiline }
if FMultiline<>Value then
begin
FMultiline := Value;
RecreateWnd;
end { FMultiline<>Value };
end; { TMultilineButton.SetMultiline }
end.