INNO设置:“关于”按钮位置

时间:2014-02-18 18:48:54

标签: inno-setup

我在组件页面中的“关于”按钮出现问题。 它在第一页中工作正常,当它较小但在这部分看起来像这样(见下面的截图)。

enter image description here

代码就是这个:

    [Setup]
    AppName=My Program
    AppVersion=1.5
    DefaultDirName={pf}\My Program
    DefaultGroupName=My Program
    UninstallDisplayIcon={app}\MyProg.exe
    OutputDir=userdocs:Inno Setup Examples Output


    [Types]
    Name: "full"; Description: "Full installation"
    Name: "compact"; Description: "Compact installation"
    Name: "custom"; Description: "Custom installation"; Flags: iscustom

    [Components]
    Name: "program"; Description: "Program Files"; Types: full compact custom; Flags: fixed
    Name: "help"; Description: "Help File"; Types: full
    Name: "readme"; Description: "Readme File"; Types: full
    Name: "readme\en"; Description: "English"; Flags: exclusive
    Name: "readme\de"; Description: "German"; Flags: exclusive

    [Code]
    procedure AboutButtonOnClick(Sender: TObject);
    begin
      MsgBox('This is a demo of how to create a button!', mbInformation, mb_Ok);
    end;

    procedure CreateAboutButton(ParentForm: TSetupForm; CancelButton: TNewButton);
    var
      AboutButton: TNewButton;
    begin
      AboutButton := TNewButton.Create(ParentForm);
      AboutButton.Left := ParentForm.ClientWidth - CancelButton.Left - CancelButton.Width;
      AboutButton.Top := CancelButton.Top;
      AboutButton.Width := CancelButton.Width;
      AboutButton.Height := CancelButton.Height;
      AboutButton.Caption := '&About...';
      AboutButton.OnClick := @AboutButtonOnClick;
      AboutButton.Parent := ParentForm;
    end;


    procedure InitializeWizard1();
    begin
      CreateAboutButton(WizardForm, WizardForm.CancelButton);
    end;

    type
      TPositionStorage = array of Integer;

    var
      CompPageModified: Boolean;
      CompPagePositions: TPositionStorage;

    procedure SaveComponentsPage(out Storage: TPositionStorage);
    begin
      SetArrayLength(Storage, 10);

      Storage[0] := WizardForm.Height;
      Storage[1] := WizardForm.NextButton.Top;
      Storage[2] := WizardForm.BackButton.Top;
      Storage[3] := WizardForm.CancelButton.Top;
      Storage[4] := WizardForm.ComponentsList.Height;
      Storage[5] := WizardForm.OuterNotebook.Height;
      Storage[6] := WizardForm.InnerNotebook.Height;
      Storage[7] := WizardForm.Bevel.Top;
      Storage[8] := WizardForm.BeveledLabel.Top;
      Storage[9] := WizardForm.ComponentsDiskSpaceLabel.Top;
    end;

    procedure LoadComponentsPage(const Storage: TPositionStorage;
      HeightOffset: Integer);
    begin
      if GetArrayLength(Storage) <> 10 then
        RaiseException('Invalid storage array length.');

      WizardForm.Height := Storage[0] + HeightOffset;
      WizardForm.NextButton.Top := Storage[1] + HeightOffset;
      WizardForm.BackButton.Top := Storage[2] + HeightOffset;
      WizardForm.CancelButton.Top := Storage[3] + HeightOffset;
      WizardForm.ComponentsList.Height := Storage[4] + HeightOffset;
      WizardForm.OuterNotebook.Height := Storage[5] + HeightOffset;
      WizardForm.InnerNotebook.Height := Storage[6] + HeightOffset;
      WizardForm.Bevel.Top := Storage[7] + HeightOffset;
      WizardForm.BeveledLabel.Top := Storage[8] + HeightOffset;
      WizardForm.ComponentsDiskSpaceLabel.Top := Storage[9] + HeightOffset;
    end;

    procedure InitializeWizard2();
    begin
      CompPageModified := False;
    end;

    procedure CurPageChanged(CurPageID: Integer);
    begin
      if CurpageID = wpSelectComponents then
      begin
        SaveComponentsPage(CompPagePositions);
        LoadComponentsPage(CompPagePositions, 200);
        CompPageModified := True;
      end
      else
      if CompPageModified then
      begin
        LoadComponentsPage(CompPagePositions, 0);
        CompPageModified := False;
      end;
    end;

       procedure InitializeWizard();
       begin 
        InitializeWizard1();
        InitializeWizard2();
       end;

有人能帮帮我吗?非常感谢先进。

2 个答案:

答案 0 :(得分:1)

由于缺少Anchors属性,因此在调整表单大小时,您必须自己移动该按钮。因此,您可以在脚本中执行的操作是发布按钮实例并扩展按钮垂直位置的现有位置存储。在代码中它可能如下所示:

[Setup]
AppName=My Program
AppVersion=1.5
DefaultDirName={pf}\My Program
DefaultGroupName=My Program
UninstallDisplayIcon={app}\MyProg.exe
OutputDir=userdocs:Inno Setup Examples Output

[Types]
Name: "full"; Description: "Full installation"
Name: "compact"; Description: "Compact installation"
Name: "custom"; Description: "Custom installation"; Flags: iscustom

[Components]
Name: "program"; Description: "Program Files"; Types: full compact custom; Flags: fixed
Name: "help"; Description: "Help File"; Types: full
Name: "readme"; Description: "Readme File"; Types: full
Name: "readme\en"; Description: "English"; Flags: exclusive
Name: "readme\de"; Description: "German"; Flags: exclusive

[Code]
type
  TPositionStorage = array of Integer;

var
  AboutButton: TNewButton;
  CompPageModified: Boolean;
  CompPagePositions: TPositionStorage;

procedure AboutButtonOnClick(Sender: TObject);
begin
  MsgBox('This is a demo of how to create a button!', mbInformation, mb_Ok);
end;

function CreateAboutButton(ParentForm: TSetupForm; CancelButton: TNewButton): TNewButton;
begin
  Result := TNewButton.Create(ParentForm);
  Result.Left := ParentForm.ClientWidth - CancelButton.Left - CancelButton.Width;
  Result.Top := CancelButton.Top;
  Result.Width := CancelButton.Width;
  Result.Height := CancelButton.Height;
  Result.Caption := '&About...';
  Result.OnClick := @AboutButtonOnClick;
  Result.Parent := ParentForm;
end;

procedure SaveComponentsPage(out Storage: TPositionStorage);
begin
  SetArrayLength(Storage, 11);

  Storage[0] := AboutButton.Top;
  Storage[1] := WizardForm.Height;
  Storage[2] := WizardForm.NextButton.Top;
  Storage[3] := WizardForm.BackButton.Top;
  Storage[4] := WizardForm.CancelButton.Top;
  Storage[5] := WizardForm.ComponentsList.Height;
  Storage[6] := WizardForm.OuterNotebook.Height;
  Storage[7] := WizardForm.InnerNotebook.Height;
  Storage[8] := WizardForm.Bevel.Top;
  Storage[9] := WizardForm.BeveledLabel.Top;
  Storage[10] := WizardForm.ComponentsDiskSpaceLabel.Top;  
end;

procedure LoadComponentsPage(const Storage: TPositionStorage;
  HeightOffset: Integer);
begin
  if GetArrayLength(Storage) <> 11 then
    RaiseException('Invalid storage array length.');

  AboutButton.Top := Storage[0] + HeightOffset;
  WizardForm.Height := Storage[1] + HeightOffset;
  WizardForm.NextButton.Top := Storage[2] + HeightOffset;
  WizardForm.BackButton.Top := Storage[3] + HeightOffset;
  WizardForm.CancelButton.Top := Storage[4] + HeightOffset;
  WizardForm.ComponentsList.Height := Storage[5] + HeightOffset;
  WizardForm.OuterNotebook.Height := Storage[6] + HeightOffset;
  WizardForm.InnerNotebook.Height := Storage[7] + HeightOffset;
  WizardForm.Bevel.Top := Storage[8] + HeightOffset;
  WizardForm.BeveledLabel.Top := Storage[9] + HeightOffset;
  WizardForm.ComponentsDiskSpaceLabel.Top := Storage[10] + HeightOffset;  
end;

procedure CurPageChanged(CurPageID: Integer);
begin
  if CurpageID = wpSelectComponents then
  begin
    SaveComponentsPage(CompPagePositions);
    LoadComponentsPage(CompPagePositions, 200);
    CompPageModified := True;
  end
  else
  if CompPageModified then
  begin
    LoadComponentsPage(CompPagePositions, 0);
    CompPageModified := False;
  end;
end;

procedure InitializeWizard();
begin 
  CompPageModified := False;
  AboutButton := CreateAboutButton(WizardForm, WizardForm.CancelButton);
end;

答案 1 :(得分:0)

在我的情况下,我在后面和下一行的同一行放了一个约按钮并取消按钮。 通过这种方式调整页面大小并不重要。 代码如下:

 // Create an About button
 AboutButton := TButton.Create(WizardForm);
 with AboutButton do
  begin
   Parent   := WizardForm;
   Left     := WizardForm.ClientWidth - CancelButton.Left - CommonWidth;
   Top      := CancelButton.Top;
   Width    := CommonWidth;
   Height   := CommonHeight;
   Caption  := ExpandConstant('{cm:About}');
   OnClick  := @HelpButtonClick;
   ShowHint := True;
   Hint     := ExpandConstant('{cm:AboutHint}');
   Name     := 'AboutButton';
  end;

在初始化设置例程中,我将行:

CommonWidth           := ScaleX(75); // Standard width for new buttons
CommonHeight          := ScaleY(23); // Standard heigth for new buttons