Placing image/control on Inno Setup custom page

inno-setup, pascalscript

Solution

That's what `TWizardPage.Surface` of type `TNewNotebookPage` is for.

with BtnImage do
begin
  Parent := CustomPage.Surface;
  { ... }
end;

Related questions:

- TInputDirWizardPage with Radio Buttons (Similar question about radio buttons with more code)

- Add additional controls to standard Inno Setup pages?

Also, never use absolute coordinates and sizes. Your layout will break, when the wizard is shown on high DPI/scaled display, what is quite common nowadays with "retina" displays. Use `ScaleX` and `ScaleY` functions. For the same reason, you should have images with different resolutions ready (see Inno Setup WizardImageFile looks bad with font scaling on Windows 7). Or at least scale/stretch the bitmap.

CustomPage := CreateCustomPage(wpLicense, 'Heading', 'Sub heading.');

ExtractTemporaryFile('image.bmp');

BtnImage := TBitmapImage.Create(WizardForm);
with BtnImage do
begin
  Parent := CustomPage.Surface;
  Bitmap.LoadFromFile(ExpandConstant('{tmp}')+'\image.bmp');
  AutoSize := True;
  AutoSize := False;
  Height := ScaleY(Height);
  Width := ScaleX(Width);
  Stretch := True;
  Left := ScaleX(90);
  Top := WizardForm.SelectTasksPage.Top + WizardForm.SelectTasksPage.Height -
         Height - ScaleY(8);
  Cursor := crHand;
  OnClick := @ImageOnClick;
end;

Layout on 100% zoom (96 DPI):

Layout on 150% zoom (144 DPI):

Layout on 150% zoom (144 DPI) with offset/sizes scaling and image stretching:

Problem

I'm trying to have an image on a custom page I can get the custom page to show or the image on a predefined page but not on the custom page. Problem I think is with `Parent := CustomPage.ID;`. `Parent := WizardForm.SelectTasksPage;` works though. How to do this properly? ``` procedure ImageOnClick(Sender: TObject); var ErrorCode: Integer; begin ShellExec('', 'http://test.com', '', '', SW_SHOW, ewNoWait, ErrorCode); end; var CustomPage: TWizardPage; BtnImage: TBitmapImage; procedure InitializeWizard; begin CustomPage := CreateCustomPage(wpLicense, 'Heading', 'Sub heading.'); ExtractTemporaryFile('image.bmp'); BtnImage := TBitmapImage.Create(WizardForm); with BtnImage do begin Parent := CustomPage.ID; Bitmap.LoadFromFile(ExpandConstant('{tmp}')+'\image.bmp'); AutoSize := True; Left := 90; Top := WizardForm.SelectTasksPage.Top + WizardForm.SelectTasksPage.Height - Height - 8; Cursor := crHand; OnClick := @ImageOnClick; end; end; ```

Original source

Related problems