Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ private static Color GetBorderColor(ComboBox comboBox, bool useAccent)

return useAccent
? Application.SystemVisualSettings.AccentColor
: comboBox.ForeColor;
: ModernControlColorMath.TextControlBorderColor;
}

private static int GetBorderThickness(ComboBox comboBox)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2663,10 +2663,9 @@ private protected virtual void OnNcPaint(Graphics graphics, HDC windowHdc)
int borderThickness = Math.Max(focusBorderMetrics.Width, focusBorderMetrics.Height);
int focusBandHeight = GetVisualStylesFocusBandHeight();

Color adornerColor = ForeColor;

Color clientBackColor = BackColor;
Color parentBackColor = Parent?.BackColor ?? BackColor;
Color adornerColor = ModernControlColorMath.TextControlBorderColor;

using var clientBackgroundBrush = clientBackColor.GetCachedSolidBrushScope();
using var adornerBrush = adornerColor.GetCachedSolidBrushScope();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1084,10 +1084,9 @@ private void DrawModernBorder(PaintEventArgs e)
int cornerRadius = LogicalToDeviceUnits(ModernControlVisualStyles.UpDownCornerRadius);
int borderThickness = LogicalToDeviceUnits(ModernControlVisualStyles.BorderThickness);

// The adorner (border) color matches the modern TextBox chrome, which uses the fore color.
Color adornerColor = ForeColor;
Color parentBackColor = Parent?.BackColor ?? BackColor;
Color clientBackColor = BackColor;
Color adornerColor = ModernControlColorMath.TextControlBorderColor;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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?


using var clientBackgroundBrush = clientBackColor.GetCachedSolidBrushScope();
using var adornerPen = adornerColor.GetCachedPenScope(borderThickness);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ internal static class ModernControlColorMath
private static readonly Color s_darkModeDisabledForeground = Color.FromArgb(0x88, 0x88, 0x88);
private static readonly Color s_lightModeDisabledForeground = Color.FromArgb(0xA0, 0xA0, 0xA0);

internal static Color TextControlBorderColor
=> Application.IsDarkModeEnabled
? SystemColors.WindowText
: SystemColors.WindowFrame;

Comment on lines +30 to +34

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please consider adding an XML doc like its siblings in this file?

/// <summary>
/// Gets the surface color for a disabled modern control, honoring the current color mode
/// and high contrast settings.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ public void ComboBox_ModernVisualStyles_FramesUseExpectedGeometryAndColor(

Color expectedBorder = usesAccent
? Application.SystemVisualSettings.AccentColor
: control.ForeColor;
: ModernControlColorMath.TextControlBorderColor;
Assert.True(
CountPixels(
actual,
Expand Down Expand Up @@ -642,13 +642,9 @@ public void ComboBox_ModernVisualStyles_Disabled_UsesDisabledBorderAndButtonColo

if (flatStyle != FlatStyle.Popup)
{
// Standard and Flat use the ForeColor for the border; it must be absent when disabled.
Assert.True(
CountPixels(enabledBitmap, customForeColor, channelTolerance: 16) > 0,
"Enabled ComboBox should render border with ForeColor.");
Assert.True(
CountPixels(disabledBitmap, customForeColor, channelTolerance: 16) == 0,
"Disabled ComboBox must not render border with the ForeColor.");
CountPixels(enabledBitmap, ModernControlColorMath.TextControlBorderColor, channelTolerance: 16) > 0,
"Enabled ComboBox should render border with TextControlBorderColor.");
Assert.True(
CountPixels(
disabledBitmap,
Expand Down