4

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.

Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
ees
  • 335
  • 1
  • 2
  • 11

1 Answers1

4

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;
Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
TLama
  • 75,147
  • 17
  • 214
  • 392