uses Windows;
procedure SetButtonMultiline(Button: TButtonControl; Multiline: Boolean);
var
Wnd: HWND;
Style: DWORD;
begin
Wnd := Button.Handle;
Style := GetWindowLongPtr(Wnd, GWL_STYLE);
if Multiline then
Style := Style or BS_MULTILINE
else
Style := Style and not BS_MULTILINE;
SetWindowLongPtr(Wnd, GWL_STYLE, Style);
end;
procedure SetButtonAlignment(Button: TButtonControl;
HorizontalAlignment, VerticalAlignment: TAlignment);
const
CHorizontalAlignment: array [TAlignment] of DWORD = (BS_LEFT, BS_RIGHT, BS_CENTER);
CHorizontalMask = BS_LEFT or BS_RIGHT or BS_CENTER;
CVerticalAlignment: array [TAlignment] of DWORD = (BS_TOP, BS_BOTTOM, BS_VCENTER);
CVerticalMask = BS_TOP or BS_BOTTOM or BS_VCENTER;
var
Wnd: HWND;
Style: DWORD;
begin
Wnd := Button.Handle;
Style := GetWindowLongPtr(Wnd, GWL_STYLE);
Style := Style and not CHorizontalMask or CHorizontalAlignment[HorizontalAlignment];
Style := Style and not CVerticalMask or CVerticalAlignment[VerticalAlignment];
SetWindowLongPtr(Wnd, GWL_STYLE, Style);
end;
procedure TForm1.FormCreate(Sender: TObject);
const
CButtonWidth = 120;
CButtonHeight = 80;
CAligmentLength = Ord(High(TAlignment)) - Ord(Low(TAlignment)) + 1;
CSpace = 8;
var
Button: TButton;
H, V: TAlignment;
X: Integer = CSpace;
S: string;
begin
Constraints.MinWidth := CAligmentLength * CAligmentLength * (CButtonWidth + CSpace) + CSpace;
for H in TAlignment do
for V in TAlignment do
begin
Button := TButton.Create(Self);
Button.Parent := Self;
Button.SetBounds(X, CSpace, CButtonWidth, CButtonHeight);
Inc(X, Button.Width + CSpace);
SetButtonMultiline(Button, True);
SetButtonAlignment(Button, H, V);
WriteStr(S, 'H=', H, #10, 'V=', V);
Button.Caption := S;
end;
end;