winforms icon indicating copy to clipboard operation
winforms copied to clipboard

Extend DarkMode opt-out option for multiple descendant scenarios.

Open KlausLoeffelmann opened this issue 6 months ago • 1 comments

When a control wants to automatically participate in DarkMode handling, it does so by setting the ControlStyles.ApplyThemingImplicitly flag first thing in the overridden property CreateParams.

For custom control controls, which derive von other controls than controls, and which in addition have already opted in (like ButtonBase) in to auto-DarkMode handling, this PR makes it possible for a control to opt out in the same way.

To this end, the derived custom control also needs to overwrite the CreateParams property, and then needs to clear the ApplyThemingImplicitly flag the first thing before calling the base implementation:

// In CreateParams, do this first to opt an inherited control out of dark mode handling:
SetFlags(ControlStyles.ApplyThemingImplicitly, false);

Note: It may seem redundant, but it's important to clear that flag, even if it can be assumed at this point that the flag has never been set before!

Microsoft Reviewers: Open in CodeFlow

KlausLoeffelmann avatar Jun 24 '25 00:06 KlausLoeffelmann

Codecov Report

Attention: Patch coverage is 91.66667% with 1 line in your changes missing coverage. Please review.

Project coverage is 76.61135%. Comparing base (7069b0a) to head (984f6e5). Report is 7 commits behind head on main.

Additional details and impacted files
@@                 Coverage Diff                 @@
##                main      #13642         +/-   ##
===================================================
+ Coverage   76.60680%   76.61135%   +0.00454%     
===================================================
  Files           3253        3253                 
  Lines         641011      641016          +5     
  Branches       47442       47443          +1     
===================================================
+ Hits          491058      491091         +33     
+ Misses        146302      146275         -27     
+ Partials        3651        3650          -1     
Flag Coverage Δ
Debug 76.61135% <91.66667%> (+0.00454%) :arrow_up:
integration 18.99664% <91.66667%> (+0.00524%) :arrow_up:
production 51.07506% <91.66667%> (+0.01057%) :arrow_up:
test 97.41186% <ø> (ø)
unit 48.45300% <91.66667%> (+0.01028%) :arrow_up:

Flags with carried forward coverage won't be shown. Click here to find out more.

:rocket: New features to boost your workflow:
  • :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • :package: JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

codecov[bot] avatar Jun 24 '25 01:06 codecov[bot]