如何确定容器控件(TPanel)的正确高度?
How to determine the right height for container controls (TPanel)?
到目前为止,这是我的自定义页面定义:
var
{ Backup Settings Page & Controls }
pageAutoBackup: TWizardPage;
btnSelectBackupFolder: TNewButton;
textBackupFolder: TNewEdit;
lblWhereToBackup: TLabel;
lblPromptMode: TLabel;
comboPromptMode: TNewComboBox;
lblReminder: TLabel;
radioBackupModeManual: TNewRadioButton;
radioBackupModeAuto: TNewRadioButton;
lblHowToBackup: TLabel;
radioBackupHowEssential: TNewRadioButton;
radioBackupHowComplete: TNewRadioButton;
radioBackupHowNone: TNewRadioButton;
lblWhatToBackup: TLabel;
panelWhatToPackup: TPanel;
panelHowToPackup: TPanel;
function pageAutoBackup_CreatePage(PreviousPageId: Integer): Integer;
begin
pageAutoBackup := CreateCustomPage(PreviousPageId, 'Automatic Backup', 'Configure automatic backup settings.');
{ panelWhatToPackup (TPanel) }
panelWhatToPackup := TPanel.Create(pageAutoBackup);
panelWhatToPackup.Caption := '';
panelWhatToPackup.BevelOuter := bvNone;
panelWhatToPackup.BevelInner := bvNone; { default }
panelWhatToPackup.BevelKind := bkNone;
panelWhatToPackup.Parent := pageAutoBackup.Surface;
panelWhatToPackup.Enabled := True;
panelWhatToPackup.Visible := True;
panelWhatToPackup.Left := ScaleX(0);
panelWhatToPackup.Top := ScaleY(0);
panelWhatToPackup.Width := pageAutoBackup.Surface.Width;
panelWhatToPackup.Height := ScaleY(90);
panelWhatToPackup.Anchors := [akLeft, akRight];
{ lblWhatToBackup (TLabel) }
lblWhatToBackup := TLabel.Create(pageAutoBackup);
lblWhatToBackup.Parent := panelWhatToPackup;
lblWhatToBackup.Enabled := True;
lblWhatToBackup.Visible := True;
lblWhatToBackup.Width := panelWhatToPackup.Width;
lblWhatToBackup.Font.Color := [=10=]0000;
lblWhatToBackup.Color := $F0F0F0;
lblWhatToBackup.Caption := 'What to backup:';
{ radioBackupHowNone (TNewRadioButton) }
radioBackupHowNone := TNewRadioButton.Create(pageAutoBackup);
radioBackupHowNone.Parent := panelWhatToPackup;
radioBackupHowNone.Enabled := True;
radioBackupHowNone.Visible := True;
radioBackupHowNone.Top := lblWhatToBackup.Top + lblWhatToBackup.Height + ScaleY(2);
radioBackupHowNone.Width := panelWhatToPackup.Width;
radioBackupHowNone.Checked := False;
radioBackupHowNone.Font.Color := [=10=]0000;
radioBackupHowNone.Color := $F0F0F0;
radioBackupHowNone.Caption := 'Don''t perform any backup when the program shuts down';
{ radioBackupHowComplete (TNewRadioButton) }
radioBackupHowComplete := TNewRadioButton.Create(pageAutoBackup);
radioBackupHowComplete.Parent := panelWhatToPackup;
radioBackupHowComplete.Enabled := True;
radioBackupHowComplete.Visible := True;
radioBackupHowComplete.Top := radioBackupHowNone.Top + radioBackupHowNone.Height + ScaleY(2);
radioBackupHowComplete.Width := panelWhatToPackup.Width;
radioBackupHowComplete.Checked := False;
radioBackupHowComplete.Font.Color := [=10=]0000;
radioBackupHowComplete.Color := $F0F0F0;
radioBackupHowComplete.Caption := 'Make a complete backup when the program shuts down';
{ radioBackupHowEssential (TNewRadioButton) }
radioBackupHowEssential := TNewRadioButton.Create(pageAutoBackup);
radioBackupHowEssential.Parent := panelWhatToPackup;
radioBackupHowEssential.Enabled := True;
radioBackupHowEssential.Visible := True;
radioBackupHowEssential.Top := radioBackupHowComplete.Top + radioBackupHowComplete.Height + ScaleY(2);
radioBackupHowEssential.Width := panelWhatToPackup.Width;
radioBackupHowEssential.Checked := False;
radioBackupHowEssential.Font.Color := [=10=]0000;
radioBackupHowEssential.Color := $F0F0F0;
radioBackupHowEssential.Caption := 'Only make an essential backup when the program shuts down';
{ panelHowToPackup (TPanel) }
panelHowToPackup := TPanel.Create(pageAutoBackup);
panelHowToPackup.Caption := '';
panelHowToPackup.BevelOuter := bvNone;
panelHowToPackup.BevelInner := bvNone; { default }
panelHowToPackup.BevelKind := bkNone;
panelHowToPackup.Parent := pageAutoBackup.Surface;
panelHowToPackup.Enabled := True;
panelHowToPackup.Visible := True;
panelHowToPackup.Top := panelWhatToPackup.Top + panelWhatToPackup.Height + ScaleY(2);
panelHowToPackup.Width := pageAutoBackup.Surface.Width;
panelHowToPackup.Height := ScaleY(100);
panelHowToPackup.Anchors := [akLeft, akRight];
{ lblHowToBackup (TLabel) }
lblHowToBackup := TLabel.Create(pageAutoBackup);
lblHowToBackup.Parent := panelHowToPackup;
lblHowToBackup.Enabled := True;
lblHowToBackup.Visible := True;
lblHowToBackup.Width := panelHowToPackup.Width;
lblHowToBackup.Font.Color := [=10=]0000;
lblHowToBackup.Color := $F0F0F0;
lblHowToBackup.Caption := 'How to backup:';
{ radioBackupModeAuto (TNewRadioButton) }
radioBackupModeAuto := TNewRadioButton.Create(pageAutoBackup);
radioBackupModeAuto.Parent := panelHowToPackup;
radioBackupModeAuto.Enabled := True;
radioBackupModeAuto.Visible := True;
radioBackupModeAuto.Left := ScaleX(0);
radioBackupModeAuto.Top := lblHowToBackup.Top + lblHowToBackup.Height + ScaleY(2);
radioBackupModeAuto.Width := panelHowToPackup.Width;
radioBackupModeAuto.Checked := False;
radioBackupModeAuto.Font.Color := [=10=]0000;
radioBackupModeAuto.Color := $F0F0F0;
radioBackupModeAuto.Caption := 'Perform automatically when the program is shut down';
{ radioBackupModeManual (TNewRadioButton) }
radioBackupModeManual := TNewRadioButton.Create(pageAutoBackup);
radioBackupModeManual.Parent := panelHowToPackup;
radioBackupModeManual.Enabled := True;
radioBackupModeManual.Visible := True;
radioBackupModeManual.Top := radioBackupModeAuto.Top + radioBackupModeAuto.Height + ScaleY(2);
radioBackupModeManual.Width := panelHowToPackup.Width;
radioBackupModeManual.Checked := False;
radioBackupModeManual.Font.Color := [=10=]0000;
radioBackupModeManual.Color := $F0F0F0;
radioBackupModeManual.Caption := 'Prompt the user when the program is shut down';
{ lblPromptMode (TLabel) }
lblPromptMode := TLabel.Create(pageAutoBackup);
lblPromptMode.Parent := panelHowToPackup;
lblPromptMode.Enabled := True;
lblPromptMode.Visible := True;
lblPromptMode.Top := radioBackupModeManual.Top + radioBackupModeManual.Height + ScaleY(2);
lblPromptMode.Width := panelHowToPackup.Width;
lblPromptMode.Font.Color := [=10=]0000;
lblPromptMode.Color := $F0F0F0;
lblPromptMode.Caption := 'Also prompt to backup at the following intervals while the application is running:';
{ comboPromptMode (TNewComboBox) }
comboPromptMode := TNewComboBox.Create(pageAutoBackup);
comboPromptMode.Parent := panelHowToPackup;
comboPromptMode.Style := csDropDownList;
comboPromptMode.Enabled := True;
comboPromptMode.Visible := True;
comboPromptMode.Top := lblPromptMode.Top + lblPromptMode.Height + ScaleY(2);
comboPromptMode.Width := panelHowToPackup.Width;
comboPromptMode.Font.Color := [=10=]0000;
comboPromptMode.ItemIndex := 0;
comboPromptMode.Color := $FFFFFF;
comboPromptMode.Items.Add('Never prompt to backup');
comboPromptMode.Items.Add('Prompt to backup everyday');
comboPromptMode.Items.Add('Prompt to backup once a week');
comboPromptMode.Items.Add('Prompt to backup once a month');
comboPromptMode.Anchors := [akLeft, akRight];
{ lblWhereToBackup (TLabel) }
lblWhereToBackup := TLabel.Create(pageAutoBackup);
lblWhereToBackup.Parent := pageAutoBackup.Surface;
lblWhereToBackup.Enabled := True;
lblWhereToBackup.Visible := True;
lblWhereToBackup.Top := panelHowToPackup.Top + panelHowToPackup.Height + ScaleY(2);
lblWhereToBackup.Width := panelHowToPackup.Width;
lblWhereToBackup.Font.Color := [=10=]0000;
lblWhereToBackup.Color := $F0F0F0;
lblWhereToBackup.Caption := 'Where to backup:';
lblWhereToBackup.Anchors := [akLeft, akRight, akBottom];
{ textBackupFolder (TNewEdit) }
textBackupFolder := TNewEdit.Create(pageAutoBackup);
textBackupFolder.Parent := pageAutoBackup.Surface;
textBackupFolder.Enabled := True;
textBackupFolder.Visible := True;
textBackupFolder.Top := lblWhereToBackup.Top + lblWhereToBackup.Height + ScaleY(2);
textBackupFolder.Width := ScaleX(335);
textBackupFolder.Font.Color := [=10=]0000;
textBackupFolder.Color := $F0F0F0;
textBackupFolder.Anchors := [akLeft, akRight, akBottom];
{ btnSelectBackupFolder (TNewButton) }
btnSelectBackupFolder := TNewButton.Create(pageAutoBackup);
btnSelectBackupFolder.Parent := pageAutoBackup.Surface;
btnSelectBackupFolder.Enabled := True;
btnSelectBackupFolder.Visible := True;
btnSelectBackupFolder.Left := ScaleX(340);
btnSelectBackupFolder.Top := textBackupFolder.Top;
btnSelectBackupFolder.Width := ScaleX(75);
btnSelectBackupFolder.Caption := 'Browse ...';
btnSelectBackupFolder.Anchors := [akRight, akBottom];
btnSelectBackupFolder.OnClick := @btnSelectBackupFolder_Click;
Result := pageAutoBackup.ID;
end;
这是最小尺寸的样子:
由于有限 space 我决定删除其中一个静态标签,因为它并不是真正需要的。
这是调整大小后的样子:
看起来不错。我的查询涉及一些特定大小的控件:
我不得不手动计算 TPanels
的高度,还是我的逻辑有误?我现在意识到 "Where to Backup" 控件只是第二个面板的一部分。我应该加三分之一吗?我只是不知道如何计算面板覆盖其上的控件所需的高度。
您已经相对于之前的控件正确放置了控件。
所以使用相同的逻辑来调整面板的大小。放置最后一个控件后,查询其位置(底部边缘),添加一些边距,并将其用于面板高度。
panelWhatToPackup.ClientHeight :=
radioBackupHowEssential.Top + radioBackupHowEssential.Height + ScaleY(8);
有一个警告:运行 时在 Inno Setup 中创建的复选框和单选按钮不会自动缩放。您必须以编程方式更正他们的身高:
到目前为止,这是我的自定义页面定义:
var
{ Backup Settings Page & Controls }
pageAutoBackup: TWizardPage;
btnSelectBackupFolder: TNewButton;
textBackupFolder: TNewEdit;
lblWhereToBackup: TLabel;
lblPromptMode: TLabel;
comboPromptMode: TNewComboBox;
lblReminder: TLabel;
radioBackupModeManual: TNewRadioButton;
radioBackupModeAuto: TNewRadioButton;
lblHowToBackup: TLabel;
radioBackupHowEssential: TNewRadioButton;
radioBackupHowComplete: TNewRadioButton;
radioBackupHowNone: TNewRadioButton;
lblWhatToBackup: TLabel;
panelWhatToPackup: TPanel;
panelHowToPackup: TPanel;
function pageAutoBackup_CreatePage(PreviousPageId: Integer): Integer;
begin
pageAutoBackup := CreateCustomPage(PreviousPageId, 'Automatic Backup', 'Configure automatic backup settings.');
{ panelWhatToPackup (TPanel) }
panelWhatToPackup := TPanel.Create(pageAutoBackup);
panelWhatToPackup.Caption := '';
panelWhatToPackup.BevelOuter := bvNone;
panelWhatToPackup.BevelInner := bvNone; { default }
panelWhatToPackup.BevelKind := bkNone;
panelWhatToPackup.Parent := pageAutoBackup.Surface;
panelWhatToPackup.Enabled := True;
panelWhatToPackup.Visible := True;
panelWhatToPackup.Left := ScaleX(0);
panelWhatToPackup.Top := ScaleY(0);
panelWhatToPackup.Width := pageAutoBackup.Surface.Width;
panelWhatToPackup.Height := ScaleY(90);
panelWhatToPackup.Anchors := [akLeft, akRight];
{ lblWhatToBackup (TLabel) }
lblWhatToBackup := TLabel.Create(pageAutoBackup);
lblWhatToBackup.Parent := panelWhatToPackup;
lblWhatToBackup.Enabled := True;
lblWhatToBackup.Visible := True;
lblWhatToBackup.Width := panelWhatToPackup.Width;
lblWhatToBackup.Font.Color := [=10=]0000;
lblWhatToBackup.Color := $F0F0F0;
lblWhatToBackup.Caption := 'What to backup:';
{ radioBackupHowNone (TNewRadioButton) }
radioBackupHowNone := TNewRadioButton.Create(pageAutoBackup);
radioBackupHowNone.Parent := panelWhatToPackup;
radioBackupHowNone.Enabled := True;
radioBackupHowNone.Visible := True;
radioBackupHowNone.Top := lblWhatToBackup.Top + lblWhatToBackup.Height + ScaleY(2);
radioBackupHowNone.Width := panelWhatToPackup.Width;
radioBackupHowNone.Checked := False;
radioBackupHowNone.Font.Color := [=10=]0000;
radioBackupHowNone.Color := $F0F0F0;
radioBackupHowNone.Caption := 'Don''t perform any backup when the program shuts down';
{ radioBackupHowComplete (TNewRadioButton) }
radioBackupHowComplete := TNewRadioButton.Create(pageAutoBackup);
radioBackupHowComplete.Parent := panelWhatToPackup;
radioBackupHowComplete.Enabled := True;
radioBackupHowComplete.Visible := True;
radioBackupHowComplete.Top := radioBackupHowNone.Top + radioBackupHowNone.Height + ScaleY(2);
radioBackupHowComplete.Width := panelWhatToPackup.Width;
radioBackupHowComplete.Checked := False;
radioBackupHowComplete.Font.Color := [=10=]0000;
radioBackupHowComplete.Color := $F0F0F0;
radioBackupHowComplete.Caption := 'Make a complete backup when the program shuts down';
{ radioBackupHowEssential (TNewRadioButton) }
radioBackupHowEssential := TNewRadioButton.Create(pageAutoBackup);
radioBackupHowEssential.Parent := panelWhatToPackup;
radioBackupHowEssential.Enabled := True;
radioBackupHowEssential.Visible := True;
radioBackupHowEssential.Top := radioBackupHowComplete.Top + radioBackupHowComplete.Height + ScaleY(2);
radioBackupHowEssential.Width := panelWhatToPackup.Width;
radioBackupHowEssential.Checked := False;
radioBackupHowEssential.Font.Color := [=10=]0000;
radioBackupHowEssential.Color := $F0F0F0;
radioBackupHowEssential.Caption := 'Only make an essential backup when the program shuts down';
{ panelHowToPackup (TPanel) }
panelHowToPackup := TPanel.Create(pageAutoBackup);
panelHowToPackup.Caption := '';
panelHowToPackup.BevelOuter := bvNone;
panelHowToPackup.BevelInner := bvNone; { default }
panelHowToPackup.BevelKind := bkNone;
panelHowToPackup.Parent := pageAutoBackup.Surface;
panelHowToPackup.Enabled := True;
panelHowToPackup.Visible := True;
panelHowToPackup.Top := panelWhatToPackup.Top + panelWhatToPackup.Height + ScaleY(2);
panelHowToPackup.Width := pageAutoBackup.Surface.Width;
panelHowToPackup.Height := ScaleY(100);
panelHowToPackup.Anchors := [akLeft, akRight];
{ lblHowToBackup (TLabel) }
lblHowToBackup := TLabel.Create(pageAutoBackup);
lblHowToBackup.Parent := panelHowToPackup;
lblHowToBackup.Enabled := True;
lblHowToBackup.Visible := True;
lblHowToBackup.Width := panelHowToPackup.Width;
lblHowToBackup.Font.Color := [=10=]0000;
lblHowToBackup.Color := $F0F0F0;
lblHowToBackup.Caption := 'How to backup:';
{ radioBackupModeAuto (TNewRadioButton) }
radioBackupModeAuto := TNewRadioButton.Create(pageAutoBackup);
radioBackupModeAuto.Parent := panelHowToPackup;
radioBackupModeAuto.Enabled := True;
radioBackupModeAuto.Visible := True;
radioBackupModeAuto.Left := ScaleX(0);
radioBackupModeAuto.Top := lblHowToBackup.Top + lblHowToBackup.Height + ScaleY(2);
radioBackupModeAuto.Width := panelHowToPackup.Width;
radioBackupModeAuto.Checked := False;
radioBackupModeAuto.Font.Color := [=10=]0000;
radioBackupModeAuto.Color := $F0F0F0;
radioBackupModeAuto.Caption := 'Perform automatically when the program is shut down';
{ radioBackupModeManual (TNewRadioButton) }
radioBackupModeManual := TNewRadioButton.Create(pageAutoBackup);
radioBackupModeManual.Parent := panelHowToPackup;
radioBackupModeManual.Enabled := True;
radioBackupModeManual.Visible := True;
radioBackupModeManual.Top := radioBackupModeAuto.Top + radioBackupModeAuto.Height + ScaleY(2);
radioBackupModeManual.Width := panelHowToPackup.Width;
radioBackupModeManual.Checked := False;
radioBackupModeManual.Font.Color := [=10=]0000;
radioBackupModeManual.Color := $F0F0F0;
radioBackupModeManual.Caption := 'Prompt the user when the program is shut down';
{ lblPromptMode (TLabel) }
lblPromptMode := TLabel.Create(pageAutoBackup);
lblPromptMode.Parent := panelHowToPackup;
lblPromptMode.Enabled := True;
lblPromptMode.Visible := True;
lblPromptMode.Top := radioBackupModeManual.Top + radioBackupModeManual.Height + ScaleY(2);
lblPromptMode.Width := panelHowToPackup.Width;
lblPromptMode.Font.Color := [=10=]0000;
lblPromptMode.Color := $F0F0F0;
lblPromptMode.Caption := 'Also prompt to backup at the following intervals while the application is running:';
{ comboPromptMode (TNewComboBox) }
comboPromptMode := TNewComboBox.Create(pageAutoBackup);
comboPromptMode.Parent := panelHowToPackup;
comboPromptMode.Style := csDropDownList;
comboPromptMode.Enabled := True;
comboPromptMode.Visible := True;
comboPromptMode.Top := lblPromptMode.Top + lblPromptMode.Height + ScaleY(2);
comboPromptMode.Width := panelHowToPackup.Width;
comboPromptMode.Font.Color := [=10=]0000;
comboPromptMode.ItemIndex := 0;
comboPromptMode.Color := $FFFFFF;
comboPromptMode.Items.Add('Never prompt to backup');
comboPromptMode.Items.Add('Prompt to backup everyday');
comboPromptMode.Items.Add('Prompt to backup once a week');
comboPromptMode.Items.Add('Prompt to backup once a month');
comboPromptMode.Anchors := [akLeft, akRight];
{ lblWhereToBackup (TLabel) }
lblWhereToBackup := TLabel.Create(pageAutoBackup);
lblWhereToBackup.Parent := pageAutoBackup.Surface;
lblWhereToBackup.Enabled := True;
lblWhereToBackup.Visible := True;
lblWhereToBackup.Top := panelHowToPackup.Top + panelHowToPackup.Height + ScaleY(2);
lblWhereToBackup.Width := panelHowToPackup.Width;
lblWhereToBackup.Font.Color := [=10=]0000;
lblWhereToBackup.Color := $F0F0F0;
lblWhereToBackup.Caption := 'Where to backup:';
lblWhereToBackup.Anchors := [akLeft, akRight, akBottom];
{ textBackupFolder (TNewEdit) }
textBackupFolder := TNewEdit.Create(pageAutoBackup);
textBackupFolder.Parent := pageAutoBackup.Surface;
textBackupFolder.Enabled := True;
textBackupFolder.Visible := True;
textBackupFolder.Top := lblWhereToBackup.Top + lblWhereToBackup.Height + ScaleY(2);
textBackupFolder.Width := ScaleX(335);
textBackupFolder.Font.Color := [=10=]0000;
textBackupFolder.Color := $F0F0F0;
textBackupFolder.Anchors := [akLeft, akRight, akBottom];
{ btnSelectBackupFolder (TNewButton) }
btnSelectBackupFolder := TNewButton.Create(pageAutoBackup);
btnSelectBackupFolder.Parent := pageAutoBackup.Surface;
btnSelectBackupFolder.Enabled := True;
btnSelectBackupFolder.Visible := True;
btnSelectBackupFolder.Left := ScaleX(340);
btnSelectBackupFolder.Top := textBackupFolder.Top;
btnSelectBackupFolder.Width := ScaleX(75);
btnSelectBackupFolder.Caption := 'Browse ...';
btnSelectBackupFolder.Anchors := [akRight, akBottom];
btnSelectBackupFolder.OnClick := @btnSelectBackupFolder_Click;
Result := pageAutoBackup.ID;
end;
这是最小尺寸的样子:
由于有限 space 我决定删除其中一个静态标签,因为它并不是真正需要的。
这是调整大小后的样子:
看起来不错。我的查询涉及一些特定大小的控件:
我不得不手动计算 TPanels
的高度,还是我的逻辑有误?我现在意识到 "Where to Backup" 控件只是第二个面板的一部分。我应该加三分之一吗?我只是不知道如何计算面板覆盖其上的控件所需的高度。
您已经相对于之前的控件正确放置了控件。
所以使用相同的逻辑来调整面板的大小。放置最后一个控件后,查询其位置(底部边缘),添加一些边距,并将其用于面板高度。
panelWhatToPackup.ClientHeight :=
radioBackupHowEssential.Top + radioBackupHowEssential.Height + ScaleY(8);
有一个警告:运行 时在 Inno Setup 中创建的复选框和单选按钮不会自动缩放。您必须以编程方式更正他们的身高: