Skip to content

Label is forcibly rendered with WindowText color instead of ControlText in high contrast mode #5196

@koszeggy

Description

@koszeggy
  • .NET Core Version:
    All versions from .NET Core 3.0 to .NET 5

  • Have you experienced this same bug with .NET Framework?:
    No

Problem description:

The default color of a Label is SystemColors.ControlText. However, starting with .NET Core 3.0, it is rendered with SystemColors.WindowText color in HighContrast mode. This can produce the following issue with a high contrast color set using inverted Window/Control colors:

High contrast .NET Framework vs Core
On the left side there is the .NET Framework 4.5 version, whereas on the right the .NET 5.0. Notice the disappeared labels.

Expected behavior:

In high contrast mode, a Label with default colors should not disappear on a control that also has the default SystemColors.Control color.

Minimal repro:

  • Create a customized high contrast theme where Control and Window colors are inverses of each other.
  • Create a Form with a Label on it. Or just use this application, which is the source of the screenshot above.

Note: It's actually doesn't really make sense to create such a theme because Window/Control colors are often misused even in Windows settings but it is very useful for testing purposes.

Further remarks:
The culprit is this line of code, which is not present in the framework version. Unfortunately this solution overrides any explicitly set colors, so it cannot be fixed without overriding OnPaint or handling the Paint event.

Btw, this theme helped me to detect other issues, too; however these can be fixed by explicitly set colors:

  • A TextBox uses Window and WindowText colors, but in ReadOnly mode the background changes to Control, while text color remains WindowText. Fortunately TextBox allows explicitly set colors so I can adjust the ForeColor in ReadOnly mode
  • Similarly to Label, the default cell style of a DatagridView also uses ill-paierd colors (and also the default header cell style), but these can be overridden as well.

Metadata

Metadata

Assignees

No one assigned

    Labels

    🪲 bugProduct bug (most likely)💥 regression-previewRegression from a preview releasetenet-accessibilityMAS violation, UIA issue; problems with accessibility standards

    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