Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Inno Setup position a custom button relative to existing buttons

Tags:

inno-setup

I am aware that is possible to create a custom button on any page and position it using absolute values using the following code:

//Create the About button
  AboutButton := TButton.Create(WizardForm);
  AboutButton.Caption := '&About';
  AboutButton.Width := ScaleX(75);
  AboutButton.Height := ScaleY(23);
  AboutButton.Left := WizardForm.InfoAfterPage.Left + 10;
  AboutButton.Top := WizardForm.InfoAfterPage.Height + 90;
  AboutButton.OnClick := @AboutButtonClick;
  AboutButton.Parent := WizardForm.NextButton.Parent;

The only problem with this is that since it uses absolute values for positioning, if the user has Windows scaling switched on (under Screen Resolution > Make text and other items larger or smaller) and scaling is set to Medium 125%, the buttons then appear out of alignment with the other built-in buttons resulting in a nasty mess. Therefore, is there a way to position any newly created custom buttons in relation to the built-in buttons, so that they always appear in-line and as they were intended? Or is there another solution to this scaling dilemma that I am overlooking?

like image 814
Robert Wigley Avatar asked Feb 04 '15 18:02

Robert Wigley


Video Answer


1 Answers

This is how I would write it:

  AboutButton := TButton.Create(WizardForm);
  AboutButton.Caption := '&About';
  AboutButton.Left := WizardForm.InfoAfterPage.Left + (WizardForm.ClientWidth - 
   (WizardForm.CancelButton.Left + WizardForm.CancelButton.Width)); 
   // sets Left position from the Page Left 
   // + already scaled gap calculated on the basis of TLama's recommendations
  AboutButton.Width := WizardForm.NextButton.Width;   
   // sets same Width as NextButton
  AboutButton.Top := WizardForm.NextButton.Top;       
   // sets same Top position as NextButton
  AboutButton.Height := WizardForm.NextButton.Height; 
   // sets same Height as NextButton
  AboutButton.OnClick := @AboutButtonClick;
  AboutButton.Parent := WizardForm.NextButton.Parent;

Examples:

96 (Default)

120 (125%)

144 (150%)

like image 90
RobeN Avatar answered Oct 11 '22 15:10

RobeN