Skip to content

Fixes WinForms PrintPreviewControl ForeColor displays incorrectly only when set to White#14424

Open
ricardobossan wants to merge 2 commits intodotnet:mainfrom
ricardobossan:Issue_14420_PrintPreviewControl_ForeColor_White_Is_Black
Open

Fixes WinForms PrintPreviewControl ForeColor displays incorrectly only when set to White#14424
ricardobossan wants to merge 2 commits intodotnet:mainfrom
ricardobossan:Issue_14420_PrintPreviewControl_ForeColor_White_Is_Black

Conversation

@ricardobossan
Copy link
Copy Markdown
Member

@ricardobossan ricardobossan commented Mar 26, 2026

Fixes #14420

Root Cause

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 #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.

Proposed changes

  • 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.

Customer Impact

PrintPreviewControl with ForeColor set to White renders the message text as Black instead of White, both in the designer and at runtime.

Regression?

Risk

  • Minimal. Single-line change in DrawMessage. High Contrast override is unaffected.

Screenshots

Before

14420-before

After

14420-after

Test methodology

  • 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.

Test environment(s)

  • 11.0.100-preview.3.26170.106
Microsoft Reviewers: Open in CodeFlow

`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
@ricardobossan ricardobossan self-assigned this Mar 26, 2026
@ricardobossan ricardobossan requested a review from a team as a code owner March 26, 2026 23:31
@ricardobossan ricardobossan added the waiting-review This item is waiting on review by one or more members of team label Mar 26, 2026
@dotnet-policy-service dotnet-policy-service bot added waiting-author-feedback The team requires more information from the author and removed waiting-author-feedback The team requires more information from the author labels Mar 27, 2026
@ricardobossan ricardobossan force-pushed the Issue_14420_PrintPreviewControl_ForeColor_White_Is_Black branch from c9af0d2 to ae86f32 Compare March 31, 2026 23:09
Copy link
Copy Markdown
Member

@LeafShi1 LeafShi1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-area-label waiting-review This item is waiting on review by one or more members of team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

WinForms PrintPreviewControl ForeColor displays incorrectly only when set to White

4 participants