Search code examples
inno-setupdpi

Inno Setup correctly position a label with respect to screen DPI


I am trying to position a label above the InfoAfterPage section and have it always appear there no matter what scaling is used, just as the amount of space required shown below is positioned.

Label Position

I am using Label.Top := WizardForm.InfoAfterPage.Height - 20, but am aware that may appear out of place if the screen is scaled in any way. What is the best way to set this so that always stays in this position no matter how the screen is scaled?


Solution

  • Use ScaleY support function:

    Label.Top := WizardForm.InfoAfterPage.Height - ScaleY(20);
    

    Or even better, do not even make assumptions about the label height:

    Label.Top := WizardForm.InfoAfterPage.Height - ScaleY(7) - Label.Height;
    

    Or for your specific case, just reuse a position of the ComponentsDiskSpaceLabel:

    Label.Top := WizardForm.ComponentsDiskSpaceLabel.Top;
    

    Note that the ComponentsDiskSpaceLabel exists for a lifetime of the wizard, so you can access it anytime.