Skip to content

[HDPI] SystemAware - wrong Form.ClientSize with DPI other than 100% #12270

Closed

Description

@kirsan31

.NET version

8.0.7

Did it work in .NET Framework?

No

Did it work in any of the earlier releases of .NET Core or .NET 5+?

Behavior is identical with .Net versions from 5.0 to 8.07.
.NET Framework 4.8. have similar issues but size error is smaller.

Issue description

SystemAware (or PerMonitorV2 starting scale) will calculate wrong Form.ClientSize for dpi more than 100%.
The problem was discovered in #12132 (comment).
See screenshots.
net48
net807

Steps to reproduce

WinForms_DPI_SystemAware.zip

Activity

  1. added
    untriaged
    on Oct 4, 2024
  2. changed the title [-][HDPI] SystemAware - wrong Form.ClientSize with DPI other then 100%[/-] [+][HDPI] SystemAware - wrong Form.ClientSize with DPI other than 100%[/+] on Oct 4, 2024
  3. added
    area-HDPI-SA
    area-HDPI-PMv2
    area-HDPI
    and removed
    untriaged
    on Oct 8, 2024
  4. added this to the .NET 10.0 milestone on Oct 8, 2024
  5. self-assigned this
    on Feb 3, 2026
  6. LeafShi1 commented on Feb 6, 2026

    @LeafShi1
    Member

    The actual window size calculation method in WinForms at high DPI is not the same as the Math.Round(DeviceDpi / (double)96, 2).

    When AutoScaleMode = Font, WinForms' actual algorithm is:

    internal static SizeF GetCurrentAutoScaleFactor(SizeF currentAutoScaleDimensions, SizeF savedAutoScaleDimensions)== savedAutoScaleDimensions.IsEmpty
        ? new(1.0F, 1.0F)
        : new(currentAutoScaleDimensions.Width / savedAutoScaleDimensions.Width, currentAutoScaleDimensions.Height / savedAutoScaleDimensions.Height);
    

    savedAutoScaleDimensions is (7, 15).

    • The AutoScaleDimensions property on a form is automatically generated by the designer during form serialization. It can also be changed manually, but essentially it's a value determined by the developer at design time. This is also the "baseline value" used by WinForms to calculate scaling.

    On a 175% screen, CurrentAutoScaleDimensions = (12, 30).

    • This value is the logical size measured by Windows/GDI based on the current system font, WinForms simply reads it.

    Therefore, at 175% scaling:
    Horizontal font magnification ratio ≈ 12 / 7 = 1.714285…
    Vertical font magnification ratio = 30 / 15 = 2.0

    The calculated dimensions are: Width: 560 * 1.714285 = 960, Height: 250 * 2 = 500

  7. kirsan31 commented on Feb 6, 2026

    @kirsan31
    ContributorAuthor

    @LeafShi1 thank you. We all went to wrong direction after here 😞

  8. locked and limited conversation to collaborators on Mar 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area-HDPIarea-HDPI-PMv2area-HDPI-SA

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions