ees
ees

Reputation: 335

In Inno Setup, how do I center some text in the window?

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.

Upvotes: 4

Views: 1349

Answers (1)

TLama
TLama

Reputation: 76693

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;

Upvotes: 4

Related Questions