How to set the WizardForm size to fit the image size and even more?

36 Views Asked by At

I want to be able at runtime to change the wizardform to any size with the mouse but when I drag the mouse left right up down at some point it stops at some size and the image inside is in its original size but how do I get to this size automatically?

This is how the wizardform size with the image inside when I'm running the setup script first time:

first time running size

Then I'm using the mouse to change the wizardform size to the maximum width and height. and this is also how I want it to be when running the script first time so I will not need to do it on my own with the mouse.

the size of the wizard form after changed it with the mouse in runtime

I have two questions about it:

  1. How to be able to change in runtime with the mouse the wizard form size to any size? why it's limiting me to the size in the second image?

  2. How to get the second image automatically when running the script first time? why it's starting in a smaller size ?

Wha have I tried so far:

At the setup:

[Setup]
Compression=lzma
SolidCompression=yes
WizardStyle=modern
WizardImageFile=lightningstrike1.bmp

At the code

[Code]
const
  MaxLineWidth = 100; // Maximum width for each line of text
  LabelMargin = 20; // Adjust this value as needed

function SplitTextIntoLines(const InputText: string; MaxWidth: Integer): string;
var
  Lines: TStringList;
  Line: string;
  Words: TStringList;
  WordIdx: Integer;
  LineIdx: Integer;
begin
  Lines := TStringList.Create;
  Words := TStringList.Create;
  try
    Words.Delimiter := ' ';
    Words.StrictDelimiter := True;
    Words.DelimitedText := InputText;

    Line := '';
    for WordIdx := 0 to Words.Count - 1 do
    begin
      if Length(Line) + Length(Words[WordIdx]) + 1 <= MaxWidth then
      begin
        if Line <> '' then
          Line := Line + ' ';
        Line := Line + Words[WordIdx];
      end
      else
      begin
        Lines.Add(Line);
        Line := Words[WordIdx];
      end;
    end;

    if Line <> '' then
      Lines.Add(Line);

    Result := Lines.Text;
  finally
    Lines.Free;
    Words.Free;
  end;
end;

and last the initializewizard

procedure InitializeWizard;
var
  WelcomePage: TWizardPage;
  BitmapImage: TBitmapImage;
  ExplanationLabel: TLabel;
  ExplanationText: string;
  TextWidth: Integer;
  BackgroundImage: TBitmap;
  NewWidth: Integer; // Set the new width of the WizardForm
  NewHeight: Integer;
  ControlSpacing: Integer; // Set the spacing between controls

begin
  // Create the WelcomePage
  WelcomePage := CreateCustomPage(wpWelcome, 'Welcome to {#MyAppName} Setup', 'Please read the following information before proceeding:');

  // Create the BitmapImage control
  BitmapImage := TBitmapImage.Create(WizardForm);
  BitmapImage.Parent := WelcomePage.Surface;
  BitmapImage.Left := 0;
  BitmapImage.Top := 0;
  BitmapImage.Width := ScaleX(160); // Adjust the image width as needed
  BitmapImage.Height := ScaleY(160); // Adjust the image height as needed
  BitmapImage.Bitmap.LoadFromFile(ExpandConstant('{src}\Weather_Michmoret.bmp'));
  BitmapImage.AutoSize := True;

  // Create the BackgroundImage
  BackgroundImage := TBitmap.Create;
  BackgroundImage.LoadFromFile(ExpandConstant('{src}\Weather_Michmoret.bmp'));

  // Create the ExplanationLabel control
  ExplanationLabel := TLabel.Create(WizardForm);
  ExplanationLabel.Parent := WelcomePage.Surface;
  ExplanationLabel.Left := 0; // Adjust the left position as needed
  ExplanationLabel.Top := BitmapImage.Height + ScaleY(20); // Adjust the top position as needed
  ExplanationLabel.Width := NewWidth; // Set the label's width to match the WizardForm width
  ExplanationLabel.Height := ScaleY(100); // Adjust the label height as needed
  ExplanationLabel.Font.Size := 12;
  ExplanationLabel.Font.Color := $9900FF;
  ExplanationLabel.WordWrap := True;

  ExplanationText :=
    'Welcome to the installation of ' + ExpandConstant('{#MyAppName}') + ' ' + ExpandConstant('{#MyAppVersion}') + '.' + #13#10#13#10 +
    'This wizard will guide you through the installation process. Please click Next to continue.' + #13#10#13#10 +
    'You can choose between a Full Installation or a Custom Installation in the next step. ' +
    'In the Custom Installation, you can select the installation folder and choose to create shortcuts on the desktop and Start menu.' + #13#10#13#10 +
    'Thank you for choosing ' + ExpandConstant('{#MyAppName}') + '!';

  // Split the text into lines of a specific width
  ExplanationText := SplitTextIntoLines(ExplanationText, MaxLineWidth);

  // Set the text
  ExplanationLabel.Caption := ExplanationText;

  // Set the spacing between controls
  ControlSpacing := ScaleY(20); // Adjust the spacing as needed
  WelcomePage.Surface.ClientHeight := ExplanationLabel.Top + ExplanationLabel.Height + ControlSpacing;
end;
0

There are 0 best solutions below