Skip to content

Fix issue 11956: [Dark Mode] CheckBox in TreeView/ListView is not in dark mode after enabled SystemColorMode.Dark#14288

Open
SimonZhao888 wants to merge 5 commits intodotnet:mainfrom
SimonZhao888:Fix_issue_11956
Open

Fix issue 11956: [Dark Mode] CheckBox in TreeView/ListView is not in dark mode after enabled SystemColorMode.Dark#14288
SimonZhao888 wants to merge 5 commits intodotnet:mainfrom
SimonZhao888:Fix_issue_11956

Conversation

@SimonZhao888
Copy link
Copy Markdown
Member

@SimonZhao888 SimonZhao888 commented Feb 11, 2026

Fixes #11956

Proposed changes

Fixed an issue where the checkboxes in TreeView/ListView were not rendered correctly in dark theme. The main changes are as follows:

  • TreeView: Creates/uses UpdateCheckBoxImages to generate a state imagelist of checkboxes that fits the dark system color, and refreshes and applies it when creating control code, enabling CheckBoxes, and setting WM_SYSCOLORCHANGE.
  • ListView: Generates and applies a dark state imagelist to the checkboxes in ApplyDarkModeOnDemand, and refreshes the project state images to ensure the checkboxes display correctly in dark mode.

Customer Impact

  • The checkboxes in TreeView/ListView render correctly in dark theme.

Regression?

  • No

Risk

  • Minimal

Screenshots

Before

image

After

image

Test methodology

  • Manually

Test environment(s)

  • .net 11.0.100-preview.1.26078.121
Microsoft Reviewers: Open in CodeFlow

@github-actions github-actions Bot added the area-DarkMode Issues relating to Dark Mode feature label Feb 11, 2026
@codecov
Copy link
Copy Markdown

codecov Bot commented Feb 11, 2026

Codecov Report

❌ Patch coverage is 33.69565% with 61 lines in your changes missing coverage. Please review.
✅ Project coverage is 77.30967%. Comparing base (ada1700) to head (c0dd9db).
⚠️ Report is 33 commits behind head on main.

Additional details and impacted files
@@                 Coverage Diff                 @@
##                main      #14288         +/-   ##
===================================================
+ Coverage   77.22797%   77.30967%   +0.08169%     
===================================================
  Files           3279        3265         -14     
  Lines         645138      644539        -599     
  Branches       47730       47644         -86     
===================================================
+ Hits          498227      498291         +64     
+ Misses        143226      142558        -668     
- Partials        3685        3690          +5     
Flag Coverage Δ
Debug 77.30967% <33.69565%> (+0.08169%) ⬆️
integration 19.12300% <2.17391%> (+0.05010%) ⬆️
production 52.27906% <33.69565%> (+0.11715%) ⬆️
test 97.41916% <ø> (+0.01436%) ⬆️
unit 49.63815% <33.69565%> (+0.12406%) ⬆️

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@dotnet-policy-service dotnet-policy-service Bot added the draft draft PR label Feb 11, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes WinForms dark mode rendering for TreeView/ListView checkboxes when Application.SetColorMode(SystemColorMode.Dark) is enabled, aligning checkbox visuals with other controls in dark mode.

Changes:

  • TreeView: generate and apply a dark-mode-aware state imagelist for checkboxes, and refresh it on handle creation, CheckBoxes enablement, and WM_SYSCOLORCHANGE.
  • ListView: generate and apply a dark-mode-aware state imagelist for checkboxes during dark mode theme application, and refresh item state images to ensure correct visuals.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
src/System.Windows.Forms/System/Windows/Forms/Controls/TreeView/TreeView.cs Adds UpdateCheckBoxImages() to supply themed checkbox state images and refresh them on relevant lifecycle/system events.
src/System.Windows.Forms/System/Windows/Forms/Controls/ListView/ListView.cs Adds a dark-mode state imagelist for checkbox rendering during ApplyDarkModeOnDemand().

Comment thread src/System.Windows.Forms/System/Windows/Forms/Controls/TreeView/TreeView.cs Outdated
@SimonZhao888 SimonZhao888 marked this pull request as ready for review February 12, 2026 01:53
@SimonZhao888 SimonZhao888 requested a review from a team as a code owner February 12, 2026 01:53
@SimonZhao888 SimonZhao888 changed the title Fix issue 11956 Fix issue 11956: [Dark Mode] CheckBox in TreeView/ListView is not in dark mode after enabled SystemColorMode.Dark Feb 12, 2026
@dotnet-policy-service dotnet-policy-service Bot removed the draft draft PR label Feb 12, 2026
LeafShi1
LeafShi1 previously approved these changes Mar 9, 2026
@LeafShi1 LeafShi1 self-requested a review March 9, 2026 06:32
ricardobossan
ricardobossan previously approved these changes Mar 9, 2026
…after setting an image for a TreeView node.
@SimonZhao888 SimonZhao888 dismissed stale reviews from ricardobossan and LeafShi1 via c0dd9db March 11, 2026 00:56
LeafShi1
LeafShi1 previously approved these changes Mar 12, 2026
ricardobossan
ricardobossan previously approved these changes Mar 13, 2026
@KlausLoeffelmann
Copy link
Copy Markdown
Member

Hi @SimonZhao888, thanks for tackling the TreeView/ListView checkbox dark-mode rendering — nice work on the visual-styles approach! A few items I'd like us to address before merging:

  1. Bitmap resource leak in ListView.UpdateDarkModeCheckBoxImages — The bitmaps returned by CreateDarkModeCheckBoxBitmap are passed directly to imageList.Images.Add() but are never disposed. ImageList.Images.Add copies the image data into the native HIMAGELIST; the managed Bitmap still needs to be cleaned up. Compare with the TreeView code where you correctly use using Bitmap uncheckedBitmap = new(...). Please wrap or dispose the returned bitmaps after adding them.

  2. Bitmap resource leak in TreeView.UpdateCheckBoxImages (placeholder) — The placeholder bitmap (new Bitmap(size, size)) added at index 0 is also never disposed. Consider wrapping it in a using declaration.

  3. TreeView.UpdateCheckBoxImages runs in light mode too — The method has no Application.IsDarkModeEnabled guard, so it replaces the native checkbox images on every OnHandleCreated, WM_SYSCOLORCHANGE, and CheckBoxes setter call regardless of theme. Since CheckBoxRenderer.DrawCheckBoxWithVisualStyles should produce theme-correct glyphs this may be intentional, but please confirm it doesn't regress the default light-mode appearance.

  4. ListView.UpdateDarkModeCheckBoxImages is only called from ApplyDarkModeOnDemand — If the user toggles CheckBoxes while the control is already in dark mode, will this method be invoked? The TreeView wires it up in the CheckBoxes setter; the ListView does not appear to.

(Copilot co-authored on Klaus' behalf.)

@SimonZhao888
Copy link
Copy Markdown
Member Author

Hi @SimonZhao888, thanks for tackling the TreeView/ListView checkbox dark-mode rendering — nice work on the visual-styles approach! A few items I'd like us to address before merging:

  1. Bitmap resource leak in ListView.UpdateDarkModeCheckBoxImages — Done.
  2. Bitmap resource leak in TreeView.UpdateCheckBoxImages (placeholder) — Done.
  3. TreeView.UpdateCheckBoxImages runs in light mode too — Done.
  4. ListView.UpdateDarkModeCheckBoxImages is only called from ApplyDarkModeOnDemand — Done.

@SimonZhao888 SimonZhao888 dismissed stale reviews from ricardobossan and LeafShi1 via 2498bbe April 9, 2026 03:19
@SimonZhao888 SimonZhao888 added the waiting-review This item is waiting on review by one or more members of team label Apr 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-DarkMode Issues relating to Dark Mode feature 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.

[Dark Mode] CheckBox in TreeView/ListView is not in dark mode after enabled SystemColorMode.Dark

5 participants