Fixes WinForms PrintPreviewControl ForeColor displays incorrectly only when set to White#14424
Open
ricardobossan wants to merge 2 commits intodotnet:mainfrom
Conversation
`ResetForeColor()` sets the default `ForeColor` to `Color.White`. `ShouldSerializeForeColor()` returns `false` when `ForeColor` equals `Color.White`, as it is indistinguishable from the default. In `DrawMessage`, the fix introduced by dotnet#13863 used `ShouldSerializeForeColor() ? ForeColor : SystemColors.ControlText`, which causes any explicitly set White `ForeColor` to fall back to `SystemColors.ControlText` (Black), since it matches the default value. - In `DrawMessage`, replace `ShouldSerializeForeColor() ? ForeColor : SystemColors.ControlText` with `ForeColor` directly. Since the default is already `Color.White` (set by `ResetForeColor`), this is correct for all cases: default, explicitly set White, and any other custom color. `PrintPreviewControl` with `ForeColor` set to `White` renders the message text as Black instead of White, both in the designer and at runtime. - Yes, introduced in dotnet#13863. - Minimal. Single-line change in `DrawMessage`. High Contrast override is unaffected. - Manual, using the ScratchProject with a `PrintPreviewControl` set to `ForeColor = Color.White`. - Unit tests added for default ForeColor value, `ShouldSerializeForeColor` behavior with default and non-default values. - 11.0.100-preview.3.26170.106
src/test/unit/System.Windows.Forms/System/Windows/Forms/Printing/PrintPreviewControlTests.cs
Outdated
Show resolved
Hide resolved
LeafShi1
requested changes
Mar 27, 2026
src/System.Windows.Forms/System/Windows/Forms/Printing/PrintPreviewControl.cs
Outdated
Show resolved
Hide resolved
c9af0d2 to
ae86f32
Compare
SimonZhao888
approved these changes
Apr 2, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #14420
Root Cause
ResetForeColor()sets the defaultForeColortoColor.White.ShouldSerializeForeColor()returnsfalsewhenForeColorequalsColor.White, as it is indistinguishable from the default. InDrawMessage, the fix introduced by #13863 usedShouldSerializeForeColor() ? ForeColor : SystemColors.ControlText, which causes any explicitly set WhiteForeColorto fall back toSystemColors.ControlText(Black), since it matches the default value.Proposed changes
DrawMessage, replaceShouldSerializeForeColor() ? ForeColor : SystemColors.ControlTextwithForeColordirectly. Since the default is alreadyColor.White(set byResetForeColor), this is correct for all cases: default, explicitly set White, and any other custom color.Customer Impact
PrintPreviewControlwithForeColorset toWhiterenders the message text as Black instead of White, both in the designer and at runtime.Regression?
Risk
DrawMessage. High Contrast override is unaffected.Screenshots
Before
After
Test methodology
PrintPreviewControlset toForeColor = Color.White.ShouldSerializeForeColorbehavior with default and non-default values.Test environment(s)
Microsoft Reviewers: Open in CodeFlow