Fix editable control border color in NET11 visual styles - #14853
Fix editable control border color in NET11 visual styles#14853LeafShi1 wants to merge 3 commits into
Conversation
There was a problem hiding this comment.
Pull request overview
This PR fixes a VisualStylesMode.Net11 rendering issue where changing ForeColor on editable controls unintentionally changes the control border color. It centralizes “editable text control” border-color selection in ModernControlColorMath and updates the NET11 renderers for TextBoxBase, ComboBox, and UpDownBase to use this shared logic (including a dark-mode-specific border color).
Changes:
- Added shared editable-control border color selection and enabled/disabled handling in
ModernControlColorMath. - Updated
TextBoxBaseandUpDownBasemodern border rendering to use the shared border color instead ofForeColor. - Updated
ComboBox.ModernComboAdapterborder rendering to use the shared border color (and simplified border-color selection logic).
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/System.Windows.Forms/System/Windows/Forms/Rendering/ModernControlColorMath.cs | Introduces shared border color defaults and an enabled/disabled border color helper. |
| src/System.Windows.Forms/System/Windows/Forms/Controls/UpDown/UpDownBase.cs | Uses shared border color logic for NET11 modern border rendering instead of ForeColor. |
| src/System.Windows.Forms/System/Windows/Forms/Controls/TextBox/TextBoxBase.cs | Uses shared border color logic for NET11 non-client painting instead of ForeColor. |
| src/System.Windows.Forms/System/Windows/Forms/Controls/ComboBox/ComboBox.ModernComboAdapter.cs | Switches modern ComboBox border rendering to shared border color logic and simplifies the helper signature. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
d4161f5 to
f7e0624
Compare
…the border color is set separately for dark mode and light mode.
| Color adornerColor = ForeColor; | ||
| Color parentBackColor = Parent?.BackColor ?? BackColor; | ||
| Color clientBackColor = BackColor; | ||
| Color adornerColor = ModernControlColorMath.TextControlBorderColor; |
There was a problem hiding this comment.
This PR makes the same one-line change in three places, swapping the color source to ModernControlColorMath.TextControlBorderColor. In ComboBox.ModernComboAdapter.GetBorderColor (ComboBox.ModernComboAdapter.cs:412), that line sits inside a pre-existing if (!comboBox.Enabled) return ModernControlColorMath.GetDisabledBorderColor(); branch (not added by this PR, it was already there), so ComboBox picks up disabled-state handling for free:
private static Color GetBorderColor(ComboBox comboBox, bool useAccent)
{
if (!comboBox.Enabled)
{
return ModernControlColorMath.GetDisabledBorderColor();
}
return useAccent
? Application.SystemVisualSettings.AccentColor
: ModernControlColorMath.TextControlBorderColor;
}TextBoxBase.cs:2668 and UpDownBase.cs:1089 never had an equivalent branch, so the same edit there just sets adornerColor unconditionally, with no Enabled check before or after. Since this PR is already touching the same color logic in all three places, is it worth adding the same disabled branch to TextBoxBase/UpDownBase here too, so they don't diverge from ComboBox?
| internal static Color TextControlBorderColor | ||
| => Application.IsDarkModeEnabled | ||
| ? SystemColors.WindowText | ||
| : SystemColors.WindowFrame; | ||
|
|
There was a problem hiding this comment.
Please consider adding an XML doc like its siblings in this file?
Fixes #14847
Proposed changes
Introduce shared editable-control border color logic in
ModernControlColorMathand use it across NET11 editable renderers.ForeColor.TextBoxBase,ComboBox.ModernComboAdapter, andUpDownBase.Customer Impact
Regression?
Risk
Screenshots
Before
Changing ForeColor on editable controls in VisualStylesMode.Net11 also change the border color.
After
Editable-control border color is independent from ForeColor.
Light mode:
Dark mode:

Test methodology
Test environment(s)
Microsoft Reviewers: Open in CodeFlow