Reputation: 1957
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?
Upvotes: 5
Views: 1346
Reputation: 5456
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:
Upvotes: 5
Reputation: 5472
Use ScaleX() and ScaleY() on all positions/dimensions:
AboutButton.Width := ScaleX(75);
AboutButton.Height := ScaleY(23);
AboutButton.Left := ScaleX(WizardForm.InfoAfterPage.Left + 10);
AboutButton.Top := ScaleY(WizardForm.InfoAfterPage.Height + 90);
This should work properly on all DPIs.
Upvotes: 0