admin管理员组

文章数量:1125064

I have added a TBitmapImage in the welcome page of an In Inno Setup installer. When the WizardResizable setting is set to True and I resize the wizard window, the control bounds hosting the bitmap image gets resized too, and also its background color gets changed when that happens as shown in the following screen capture:

This is an unintentionally behavior from my side. How can I fix it?.

I've tried establishing AutoSize property to false, with a fixed Height and Width properties and testing the Anchors combinations, but the problem persists.

This is my actual and full code (AuthorWebsiteBitmap is the bitmap):

[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;

UPDATE

I have mitigated the unwanted color change effect this way:

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

But the ideal solution would be to avoid automatic resizing.

I have added a TBitmapImage in the welcome page of an In Inno Setup installer. When the WizardResizable setting is set to True and I resize the wizard window, the control bounds hosting the bitmap image gets resized too, and also its background color gets changed when that happens as shown in the following screen capture:

This is an unintentionally behavior from my side. How can I fix it?.

I've tried establishing AutoSize property to false, with a fixed Height and Width properties and testing the Anchors combinations, but the problem persists.

This is my actual and full code (AuthorWebsiteBitmap is the bitmap):

[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;

UPDATE

I have mitigated the unwanted color change effect this way:

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

But the ideal solution would be to avoid automatic resizing.

Share Improve this question edited 2 days ago ElektroStudios asked 2 days ago ElektroStudiosElektroStudios 20.4k37 gold badges216 silver badges448 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 2

Inno Setup automatically stretches all controls on the WelcomePage and FinishedPage pages to their full width. It seems that it does not expect custom controls there.

You have to workaround it somehow.


In your case (as there's nothing to the right of the image), an easy solution is to simply set the background color to the page color (white/window color).

AuthorWebsiteBitmap.BackColor := WizardForm.WelcomePage.Color;

Though it won't work great with the hand custor.


Another option is to place the image on a container control (e.g. TPanel). Inno Setup would resize only the container control, leaving the image instact.

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;

本文标签: pascalscriptBitmap image gets automatically resized in a Inno Setup installerStack Overflow