Skip to content

Commit d61bbdc

Browse files
committed
Update code following the suggestion
1 parent 3829ad4 commit d61bbdc

1 file changed

Lines changed: 18 additions & 14 deletions

File tree

src/System.Windows.Forms/System/Windows/Forms/Printing/PageSetupDialog.cs

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -293,23 +293,27 @@ protected override unsafe bool RunDialog(IntPtr hwndOwner)
293293
buffer.Length);
294294
}
295295

296-
if (result > 0 && int.Parse(buffer, NumberStyles.Integer, CultureInfo.InvariantCulture) == 0)
296+
if (result > 0)
297297
{
298-
toUnit = PrinterUnit.HundredthsOfAMillimeter;
298+
ReadOnlySpan<char> actualValue = buffer[..(result - 1)];
299+
if (int.TryParse(actualValue, NumberStyles.Integer, CultureInfo.InvariantCulture, out int value) && value == 0)
300+
{
301+
toUnit = PrinterUnit.HundredthsOfAMillimeter;
302+
}
299303
}
300-
}
301304

302-
// Explicitly pass the unit flag to the native dialog so it operates in the same unit system
303-
// that WinForms used when converting margins above. This ensures that the values written into
304-
// rtMargin/rtMinMargin and the values read back in UpdateSettings are always in the same unit,
305-
// regardless of how system-level and user-level locale settings may differ.
306-
if (toUnit == PrinterUnit.HundredthsOfAMillimeter)
307-
{
308-
dialogSettings.Flags |= PAGESETUPDLG_FLAGS.PSD_INHUNDREDTHSOFMILLIMETERS;
309-
}
310-
else
311-
{
312-
dialogSettings.Flags |= PAGESETUPDLG_FLAGS.PSD_INTHOUSANDTHSOFINCHES;
305+
// Explicitly pass the unit flag to the native dialog so it operates in the unit selected
306+
// by toUnit. This keeps the values written into rtMargin/rtMinMargin below and the values read
307+
// back in UpdateSettings in the same unit, regardless of how system-level and user-level locale
308+
// settings may differ.
309+
if (toUnit == PrinterUnit.HundredthsOfAMillimeter)
310+
{
311+
dialogSettings.Flags |= PAGESETUPDLG_FLAGS.PSD_INHUNDREDTHSOFMILLIMETERS;
312+
}
313+
else
314+
{
315+
dialogSettings.Flags |= PAGESETUPDLG_FLAGS.PSD_INTHOUSANDTHSOFINCHES;
316+
}
313317
}
314318

315319
if (MinMargins is not null)

0 commit comments

Comments
 (0)