问题
In Inno Setup, how do I center some text in the window? I tried making it a TLabel
and setting the Alignment
to taCenter
but it didn't have any effect. I can set the Left
and Top
with no problems.
回答1:
The Alignment property controls the horizontal placement of the text within the label. It's not used to position controls within their parent. Except Align property (which stretches controls to given space), there is no way to center controls to their parents. But you can make a function for this:
[Code]
procedure CenterInParent(Control: TControl);
begin
if Assigned(Control) and Assigned(Control.Parent) then
begin
Control.Left := (Control.Parent.Width - Control.Width) div 2;
Control.Top := (Control.Parent.Height - Control.Height) div 2;
end;
end;
procedure InitializeWizard;
var
MyPage: TWizardPage;
MyLabel: TLabel;
begin
MyPage := CreateCustomPage(wpWelcome, 'Caption', 'Description');
MyLabel := TLabel.Create(MyPage);
MyLabel.Parent := MyPage.Surface;
MyLabel.Caption := 'Hello!';
CenterInParent(MyLabel);
end;
来源:https://stackoverflow.com/questions/25384671/in-inno-setup-how-do-i-center-some-text-in-the-window