Skip to content

Fix Button click after Dark to Light color mode switch#14785

Open
abineshPalanisamy wants to merge 2 commits into
dotnet:mainfrom
abineshPalanisamy:Fix_Issue_13636
Open

Fix Button click after Dark to Light color mode switch#14785
abineshPalanisamy wants to merge 2 commits into
dotnet:mainfrom
abineshPalanisamy:Fix_Issue_13636

Conversation

@abineshPalanisamy

@abineshPalanisamy abineshPalanisamy commented Jul 20, 2026

Copy link
Copy Markdown

Fixes #13636

Proposed changes

  • Handle WM_SETTINGCHANGE with ImmersiveColorSet in Control.WndProc.
  • Raise OnSystemColorsChanged when the application color mode is set and the OS dark/light mode changes.
  • Update ButtonBase.OnSystemColorsChanged to refresh the owner-draw state.
  • Ensure Button, CheckBox, and RadioButton update their dark-mode rendering path after OS color mode changes.

Root cause

  • When the application starts in Dark mode, button-based controls initialize their rendering path based on the current dark-mode state.
  • When the OS color mode changes from Dark to Light while the application is running, WinForms receives WM_SETTINGCHANGE with ImmersiveColorSet.
  • This message was not updating the ButtonBase owner-draw state.
  • As a result, ButtonBase-derived controls could remain in an outdated rendering state after the OS color mode changed.
  • This caused Button.Click to stop firing in the Dark-to-Light transition scenario.

Customer Impact

  • Fixes an issue where Button.Click stops working after switching the Windows OS color mode from Dark to Light.
  • Ensures ButtonBase-derived controls correctly refresh their rendering state when the OS color mode changes.
  • Improves dark-mode transition behavior for Button, CheckBox, and RadioButton.
  • Preserves existing behavior for unrelated system setting changes.

Regression?

  • No

Risk

  • Low.
  • The change is limited to handling ImmersiveColorSet system setting changes and refreshing ButtonBase owner-draw state.
  • Existing WM_SETTINGCHANGE behavior is preserved for unrelated settings.
  • The fix uses the existing OnSystemColorsChanged flow instead of adding separate Button-specific system message handling.
  • The update applies only when application color mode has been configured.

Screenshots

Before

ButtonClick_Before_fix.mp4

After

ButtonClick_After_fix.mp4

Test methodology

  • Reproduced the issue with Application.SetColorMode(SystemColorMode.System).
  • Verified the issue occurs when:
    • Windows starts in Dark mode.
    • The application starts in Dark mode.
    • Windows color mode is switched from Dark to Light.
    • Button click stops working before the fix.
  • Verified that after the fix, Button click continues to work after the Dark-to-Light transition.
  • Verified Light-to-Dark transition continues to work.
  • Verified the fix across ButtonBase-derived controls:
    • Button
    • CheckBox
    • RadioButton
  • Verified multiple FlatStyle values:
    • Standard
    • System
    • Flat
    • Popup
  • Verified owner-draw and non-owner-draw paths.
  • Added unit test coverage for WM_SETTINGCHANGE with ImmersiveColorSet.
  • Added unit test coverage to ensure ButtonBase refreshes owner-draw state on system color changes.
  • Ran related WinForms unit tests to ensure no regressions were introduced.

Accessibility testing

Test environment(s)

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

Added fix for the Fix_Issue_13636
Updated the review correction and added unit test cases
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[DarkMode] Button Click not working when Swithch Window OS ColorMode

1 participant