Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 10, 2025

Proposed changes

  • Modified TabControl.StyleChildren() to only apply dark mode theme to direct children (TabPages), not descendant controls
  • Added parent check using PInvoke.GetParent() to identify direct children
  • Preserved return value of SetWindowTheme() for proper error handling

Customer Impact

  • ComboBox controls on the first TabPage now correctly display in dark mode
  • Affects applications using Application.SetColorMode(SystemColorMode.Dark) with TabControl containing ComboBox controls

Regression?

  • Yes (regression from .NET 9.0)

Risk

  • Low. Surgical fix changes only theme application scope in TabControl
  • Only affects dark mode rendering path
  • Controls with specific dark mode themes (ComboBox, etc.) now preserve their themes

Screenshots

Before

Before fix - ComboBox on first tab shows light theme

After

image

Test methodology

  • Code review completed
  • CodeQL security scan passed
  • Manual testing required on Windows to validate visual rendering

Test environment(s)

  • .NET 10.0.100

Technical Details:

The issue occurred because TabControl.ApplyDarkModeOnDemand() calls EnumChildWindows() which recursively enumerates all descendant windows. The StyleChildren callback was applying the generic DarkMode_Explorer theme to every window, overwriting ComboBox's specific DarkMode_ComboBoxButton theme for its button component.

The fix restricts theme application to only TabPage windows (direct children of TabControl), allowing controls to maintain their specific themes:

private BOOL StyleChildren(HWND handle)
{
    // Only apply theme to direct children (TabPages), not to controls within TabPages.
    HWND parent = PInvoke.GetParent(handle);
    if (parent == HWND)
    {
        return PInvoke.SetWindowTheme(handle, $"{DarkModeIdentifier}_{ExplorerThemeIdentifier}", null)
            .Succeeded;
    }

    return true;
}

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • rcxvsblobprodcus328.vsblob.vsassets.io
    • Triggering command: /home/REDACTED/work/winforms/winforms/.dotnet/dotnet /home/REDACTED/work/winforms/winforms/.dotnet/dotnet msbuild /m /nologo /clp:Summary /v:minimal /nr:true /warnaserror /p:TreatWarningsAsErrors=true /p:ContinuousIntegrationBuild=false /home/REDACTED/work/winforms/winforms/artifacts/toolset/restore.proj /t:__WriteToolsetLocation /clp:ErrorsOnly;NoSummary /p:__ToolsetLocationOutputFile=/home/REDACTED/work/winforms/winforms/artifacts/toolset/11.0.0-beta.25609.108.txt (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

This section details on the original issue you should resolve

<issue_title>[Dark Mode] the combobox refuses dark theme when on first tabpage of a tabcontrol</issue_title>
<issue_description>### .NET version

latest .NET 10.0 build

Did it work in .NET Framework?

No

Did it work in any of the earlier releases of .NET Core or .NET 5+?

This is a regression issue, not reproduce .NET 9.0

Issue description

The combobox refuses dark theme when on first tabpage of a tabcontrol
Expected Results:
Image

Actual Results:
Image

Steps to reproduce

  1. Create a .NET winforms project with a TabCpntrol control
  2. Add a Combobox contorl in the tabPage1
  3. Set app under Dark mode in program.cs file
    Application.SetColorMode(SystemColorMode.Dark);
  4. Run the application

More info:

  1. The issue can reproduce when setting the DropDownStyle as DropDown/DropDownList, not reproduce when setting the DropDownStyle as Sample</issue_description>

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Microsoft Reviewers: Open in CodeFlow

Copilot AI and others added 2 commits December 10, 2025 08:39
Co-authored-by: SimonZhao888 <133954995+SimonZhao888@users.noreply.github.com>
Co-authored-by: SimonZhao888 <133954995+SimonZhao888@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix combobox dark theme issue on first tabpage Fix ComboBox dark mode theme on first TabPage Dec 10, 2025
Copilot AI requested a review from SimonZhao888 December 10, 2025 08:44
@codecov
Copy link

codecov bot commented Dec 10, 2025

Codecov Report

❌ Patch coverage is 0% with 8 lines in your changes missing coverage. Please review.
✅ Project coverage is 77.15885%. Comparing base (ceb6911) to head (c0b6d94).

Additional details and impacted files
@@                 Coverage Diff                 @@
##                main      #14128         +/-   ##
===================================================
+ Coverage   77.15337%   77.15885%   +0.00548%     
===================================================
  Files           3279        3279                 
  Lines         645325      645331          +6     
  Branches       47720       47721          +1     
===================================================
+ Hits          497890      497930         +40     
+ Misses        143748      143713         -35     
- Partials        3687        3688          +1     
Flag Coverage Δ
Debug 77.15885% <0.00000%> (+0.00548%) ⬆️
integration 18.99499% <0.00000%> (+0.00100%) ⬆️
production 52.02862% <0.00000%> (+0.01280%) ⬆️
test 97.40749% <ø> (ø)
unit 49.47336% <0.00000%> (+0.01738%) ⬆️

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.

@SimonZhao888 SimonZhao888 marked this pull request as ready for review December 10, 2025 09:55
@SimonZhao888 SimonZhao888 requested a review from a team as a code owner December 10, 2025 09:55
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.

[Dark Mode] the combobox refuses dark theme when on first tabpage of a tabcontrol

3 participants