代码之家  ›  专栏  ›  技术社区  ›  ElektroStudios

位图图像在Inno Setup安装程序中自动调整大小

  •  1
  • ElektroStudios  · 技术社区  · 3 周前

    我添加了一个 TBitmapImage 在in-Inno安装程序的欢迎页面中。当 WizardResizable 设置为True,我调整向导窗口的大小,托管位图图像的控件边界也会调整大小,并且当发生这种情况时,其背景颜色也会发生变化,如下图所示:

    enter image description here

    这是我无意中的行为。我该怎么修?。

    我试着建立 AutoSize 属性为假,有固定 Height Width 性能和测试 Anchors 组合,但问题依然存在。

    这是我的真实完整代码( AuthorWebsiteBitmap 是位图):

    [Setup]
    WizardResizable=yes
    WizardStyle=Classic
    
    [Code]
    // - - - - - - - - - - - - - - - - - - - - - - //
    // Creates the author website related controls //
    // - - - - - - - - - - - - - - - - - - - - - - //
    procedure CreateAuthorControls(AuthorWebsiteUrl: String);
    var
      InstallerAuthorLabel: TNewStaticText;
      AuthorWebsiteLabel  : TNewStaticText;
      AuthorWebsiteBitmap : TBitmapImage;
    
    begin
      // Set AuthorWebsiteBitmap control properties...
      AuthorWebsiteBitmap          := TBitmapImage.Create(WizardForm);
      AuthorWebsiteBitmap.Parent   := WizardForm.WelcomePage;
      AuthorWebsiteBitmap.AutoSize := True;
      AuthorWebsiteBitmap.Left     := (WizardForm.WizardBitmapImage.Left + WizardForm.WizardBitmapImage.Width) + ScaleX(10);
      AuthorWebsiteBitmap.Top      := (WizardForm.WelcomeLabel2.Top + WizardForm.WelcomeLabel2.Height) - (AuthorWebsiteBitmap.Height div 2) - ScaleX(16);
      AuthorWebsiteBitmap.Cursor   := crHand
      AuthorWebsiteBitmap.OnClick  := @AuthorWebsiteControlClick;
      AuthorWebsiteBitmap.Anchors  := [akLeft, akBottom];
      AuthorWebsiteBitmap.Visible  := (AuthorWebsiteUrl <> '');
      
      ExtractTemporaryFiles('{tmp}\WizardBitmaps\AuthorWebsiteWhite.bmp');
      AuthorWebsiteBitmap.Bitmap.LoadFromFile(ExpandConstant('{tmp}\WizardBitmaps\AuthorWebsiteWhite.bmp'));
    
      // Resize WelcomeLabel2 height to be able see AuthorWebsiteBitmap control.
      WizardForm.WelcomeLabel2.Height := WizardForm.WelcomeLabel2.Height - (AuthorWebsiteBitmap.Height + ScaleY(8));
      // This will not work...
      // AuthorWebsiteBitmap.BringToFront();
    
      // Set AuthorWebsiteLabel control properties.
      AuthorWebsiteLabel         := TNewStaticText.Create(WizardForm);
      AuthorWebsiteLabel.Parent  := WizardForm.WelcomePage;
      AuthorWebsiteLabel.Left    := AuthorWebsiteBitmap.Left;
      AuthorWebsiteLabel.Top     := AuthorWebsiteBitmap.Top - ScaleY(18);
      AuthorWebsiteLabel.Cursor  := crHand;
      AuthorWebsiteLabel.OnClick := @AuthorWebsiteControlClick;
      AuthorWebsiteLabel.Anchors := [akLeft, akBottom];
      AuthorWebsiteLabel.Visible := (AuthorWebsiteUrl <> '');
      AuthorWebsiteLabel.Caption := CustomMessage('SetupOpenAuthorWebsite');
    
      // Set InstallerAuthorLabel control properties.
      InstallerAuthorLabel         := TNewStaticText.Create(WizardForm);
      InstallerAuthorLabel.Parent  := WizardForm;
      InstallerAuthorLabel.Left    := ScaleX(2);
      InstallerAuthorLabel.Top     := WizardForm.NextButton.Top + WizardForm.NextButton.Height div 2 + ScaleY(10) - ScaleY(2);
      InstallerAuthorLabel.Anchors := [akLeft, akBottom];
      InstallerAuthorLabel.Caption := CustomMessage('SetupMadeBy');
    
    end;
    
    <event('InitializeWizard')>
    procedure InitializeWizard1();
    begin
      CreateAuthorControls(ExpandConstant('{#AuthorWebsite}'));
    end;
    

    更新

    我通过以下方式减轻了不必要的颜色变化效果:

    AuthorWebsiteBitmap.BackColor := TNewNotebookPage(AuthorWebsiteBitmap.Parent).Color;
    

    但理想的解决方案是避免自动调整大小。

    1 回复  |  直到 3 周前
        1
  •  2
  •   Martin Prikryl    3 周前

    Inno Setup会自动拉伸 WelcomePage FinishedPage 将页面调整到全宽。似乎它不期望在那里有自定义控件。

    你必须设法解决它。


    在您的情况下(因为图像右侧没有任何内容),一个简单的解决方案是将背景颜色设置为页面颜色(白色/窗口颜色)。

    AuthorWebsiteBitmap.BackColor := WizardForm.WelcomePage.Color;
    

    虽然它不适合手工烹饪。


    另一种选择是将图像放置在容器控件上(例如。 TPanel ). Inno Setup只会调整容器控件的大小,留下图像实例。

    var
      AuthorWebsitePanel: TPanel;
      AuthorWebsiteBitmap : TBitmapImage;
    begin
      AuthorWebsitePanel := TPanel.Create(WizardForm);
      
      AuthorWebsitePanel.Parent := WizardForm.WelcomePage;
      AuthorWebsitePanel.Left := WizardForm.WelcomeLabel2.Left;
      AuthorWebsitePanel.Color := WizardForm.WelcomePage.Color;
      // That's what Inno Setup would do later anyway
      AuthorWebsitePanel.Width := WizardForm.WelcomeLabel2.Width;
      AuthorWebsitePanel.BevelOuter := bvNone;
    
      AuthorWebsiteBitmap := TBitmapImage.Create(WizardForm);
      AuthorWebsiteBitmap.Parent := AuthorWebsitePanel;
      AuthorWebsiteBitmap.Left := 0;
      AuthorWebsiteBitmap.Top := 0;
      ExtractTemporaryFiles('{tmp}\WizardBitmaps\AuthorWebsiteWhite.bmp');
      AuthorWebsiteBitmap.Bitmap.LoadFromFile(
        ExpandConstant('{tmp}\WizardBitmaps\AuthorWebsiteWhite.bmp'));
      AuthorWebsiteBitmap.AutoSize := True;
      AuthorWebsiteBitmap.Cursor := crHand;
      AuthorWebsiteBitmap.OnClick  := @AuthorWebsiteControlClick;
      AuthorWebsiteBitmap.Visible  := (AuthorWebsiteUrl <> '');
    
      AuthorWebsitePanel.Height := AuthorWebsiteBitmap.Height;
      AuthorWebsitePanel.Top :=
        (WizardForm.WelcomeLabel2.Top + WizardForm.WelcomeLabel2.Height) -
        AuthorWebsitePanel.Height - ScaleY(16);
      AuthorWebsitePanel.Anchors := [akLeft, akBottom];
    
      WizardForm.WelcomeLabel2.Height :=
        WizardForm.WelcomeLabel2.Height - AuthorWebsitePanel.Height;
      // ...
    end;