Skip to content

PageSetupDialog incorrectly converts Margin units from pageSetting.Margins to dialogSettings.rtMargin #14482

@MykolaKovalchuk

Description

@MykolaKovalchuk

.NET version

10.0.201

Did it work in .NET Framework?

Yes

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

Did not test.

Issue description

Method PageSetupDialog.RunDialog(IntPtr hwndOwner) incorrectly detects toUnit based on Windows regional settings.

In Windows for my user account, Language & region > Number settings, Measurement System is set to Metric. When I open PageSetupDialog from my .Net application, it displays Margins group with caption "Margins (millimeters)".
Every time I open this dialog, don't change anything, and close it - margin values are reduced until they become 0.

After analyzing PageSetupDialog.cs and PrinterUnitConvert.cs, checking values of PrintDocument.DefaultPageSettings.Margins and what is shown in the dialog fields, and doing manual calculations, I see that:

  1. In method RunDialog original values from pageSettings.Margins converted using toUnit == PrinterUnit.ThousandthsOfAnInch.
  2. In method UpdateSettings new values converted to pageSettings.Margins using fromUnit == PrinterUnit.HundredthsOfAMillimeter.

Comparing with source code for .Net Framework 4.8, I see that there is difference in getting locale info:

  • .Net Framework 4.8 checks NativeMethods.LOCALE_USER_DEFAULT - user level;
  • .Net 10 checks PInvoke.LOCALE_NAME_SYSTEM_DEFAULT - system level;

I suspect the issues is here - logic of PageSetupDialog checks system level locale settings, but dialog itself when run by Windows uses user level locale settings (and sets flag PSD_INHUNDREDTHSOFMILLIMETERS to not 0), so it results in display discrepancy and different conversion units used with original and new values.

Steps to reproduce

Set Language & region > Number settings, Measurement System on system level to U.S.,
and on user level to Metric.

Additional note: I set PageSetupDialog.EnableMetric = true;, but it does not work with both true and false.

Metadata

Metadata

Assignees

No one assigned

    Labels

    needs-area-labeluntriagedThe team needs to look at this issue in the next triage

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions