PageSetupDialog incorrectly converts Margin units from pageSetting.Margins to dialogSettings.rtMargin
untriagedneeds-area-label
### .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`.
0 条评论