Skip to content

Commit df8badc

Browse files
Fix edge cases where dark mode did not get applied for ...
* CheckBoxes, * RadioButtons
1 parent 7b45a8c commit df8badc

File tree

6 files changed

+156
-145
lines changed

6 files changed

+156
-145
lines changed

src/System.Windows.Forms/System/Windows/Forms/Controls/Buttons/ButtonInternal/DarkMode/ButtonDarkModeAdapter.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,10 +136,7 @@ internal override void PaintOver(PaintEventArgs e, CheckState state)
136136
}
137137
}
138138

139-
protected override LayoutOptions Layout(PaintEventArgs e)
140-
{
141-
return CommonLayout();
142-
}
139+
protected override LayoutOptions Layout(PaintEventArgs e) => CommonLayout();
143140

144141
private new LayoutOptions CommonLayout()
145142
{

src/System.Windows.Forms/System/Windows/Forms/Controls/Buttons/ButtonInternal/DarkMode/ButtonDarkModeRendererBase.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,12 @@ public void RenderButton(
5959
// Draw button background and get content bounds
6060
Rectangle contentBounds = DrawButtonBackground(graphics, paddedBounds, state, isDefault);
6161

62+
// Offset content bounds for Popup style when button is pressed
63+
// if (flatStyle == FlatStyle.Popup && state == PushButtonState.Pressed)
64+
// {
65+
// contentBounds.Offset(1, 1);
66+
// }
67+
6268
// Paint image and field using the provided delegates
6369
paintImage(contentBounds);
6470

@@ -68,6 +74,12 @@ public void RenderButton(
6874
false);
6975

7076
DrawFocusIndicator(graphics, bounds, isDefault);
77+
78+
// if (focused && showFocusCues)
79+
// {
80+
// // Draw focus indicator for other styles
81+
// renderer.DrawFocusIndicator(graphics, contentBounds, isDefault);
82+
// }
7183
}
7284

7385
public abstract Rectangle DrawButtonBackground(Graphics graphics, Rectangle bounds, PushButtonState state, bool isDefault);

src/System.Windows.Forms/System/Windows/Forms/Controls/Buttons/ButtonInternal/DarkMode/FlatButtonDarkModeRenderer.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ private static void DrawButtonBorder(Graphics graphics, Rectangle bounds, PushBu
137137
}
138138

139139
// For other states, draw a border with appropriate thickness
140+
// For pressed state, draw a darker border
140141
borderColor = isDefault
141142
? DarkModeButtonColors.DefaultSingleBorderColor
142143
: DarkModeButtonColors.SingleBorderColor;

src/System.Windows.Forms/System/Windows/Forms/Controls/Buttons/ButtonInternal/DarkMode/IButtonRenderer.DarkModeButtonColors.cs

Lines changed: 139 additions & 139 deletions
Original file line numberDiff line numberDiff line change
@@ -3,143 +3,143 @@
33

44
namespace System.Windows.Forms;
55

6-
/// <summary>
7-
/// Cache of colors for different button states.
8-
/// </summary>
9-
internal static class DarkModeButtonColors
10-
{
11-
// Normal Button (non-default)
12-
13-
/// <summary>
14-
/// Button background color for normal state (#2B2B2B).
15-
/// </summary>
16-
public static Color NormalBackgroundColor => Color.FromArgb(43, 43, 43); // #2B2B2B
17-
18-
/// <summary>
19-
/// Button background color for hover state (#3B3B3B).
20-
/// </summary>
21-
public static Color HoverBackgroundColor => Color.FromArgb(59, 59, 59); // #3B3B3B
22-
23-
/// <summary>
24-
/// Button background color for pressed state (#4B4B4B).
25-
/// </summary>
26-
public static Color PressedBackgroundColor => Color.FromArgb(75, 75, 75); // #4B4B4B
27-
28-
/// <summary>
29-
/// Button background color for disabled state (#252525).
30-
/// </summary>
31-
public static Color DisabledBackgroundColor => Color.FromArgb(37, 37, 37); // #252525
32-
33-
// Default Button
34-
35-
/// <summary>
36-
/// Default button background color (#2B2B2B).
37-
/// </summary>
38-
public static Color DefaultBackgroundColor => NormalBackgroundColor; // #2B2B2B
39-
40-
/// <summary>
41-
/// Default button hover background color (#3B3B3B).
42-
/// </summary>
43-
public static Color DefaultHoverBackgroundColor => HoverBackgroundColor; // #3B3B3B
44-
45-
/// <summary>
46-
/// Default button pressed background color (#4B4B4B).
47-
/// </summary>
48-
public static Color DefaultPressedBackgroundColor => PressedBackgroundColor; // #4B4B4B
49-
50-
/// <summary>
51-
/// Default button disabled background color (#252525).
52-
/// </summary>
53-
public static Color DefaultDisabledBackgroundColor => DisabledBackgroundColor; // #252525
54-
55-
// Text Colors
56-
57-
/// <summary>
58-
/// Normal text color (#E0E0E0).
59-
/// </summary>
60-
public static Color NormalTextColor => Color.FromArgb(224, 224, 224); // #E0E0E0
61-
62-
/// <summary>
63-
/// Default button text color (#FFFFFF).
64-
/// </summary>
65-
public static Color DefaultTextColor => Color.White; // #FFFFFF
66-
67-
/// <summary>
68-
/// Disabled text color (#606060, ~40% opacity).
69-
/// </summary>
70-
public static Color DisabledTextColor => Color.FromArgb(96, 96, 96); // #606060
71-
72-
/// <summary>
73-
/// Gets the single border color for a button in dark mode (#969696).
74-
/// </summary>
75-
public static Color SingleBorderColor => Color.FromArgb(150, 150, 150); // #969696
76-
776
/// <summary>
78-
/// Gets the single border color for a default button in dark mode (#D2D2D2).
79-
/// </summary>
80-
public static Color DefaultSingleBorderColor => Color.FromArgb(210, 210, 210); // #D2D2D2
81-
82-
/// <summary>
83-
/// Gets the single border color for a pressed button in dark mode (#DCDCDC).
84-
/// </summary>
85-
public static Color PressedSingleBorderColor => Color.FromArgb(220, 220, 220); // #DCDCDC
86-
87-
/// <summary>
88-
/// Button top-left border color (#555555).
89-
/// </summary>
90-
public static Color TopLeftBorderColor => Color.FromArgb(85, 85, 85); // #555555
91-
92-
/// <summary>
93-
/// Button bottom-right border color (#222222).
94-
/// </summary>
95-
public static Color BottomRightBorderColor => Color.FromArgb(34, 34, 34); // #222222
96-
97-
// Focus Colors
98-
99-
/// <summary>
100-
/// Focus indicator color (#F0F0F0).
101-
/// </summary>
102-
public static Color FocusIndicatorColor => Color.FromArgb(240, 240, 240); // #F0F0F0
103-
104-
/// <summary>
105-
/// Default button focus indicator color (#FFFFFF).
106-
/// </summary>
107-
public static Color DefaultFocusIndicatorColor => Color.White; // #FFFFFF
108-
109-
// Shadow and Highlight Colors for 3D effects
110-
111-
/// <summary>
112-
/// Shadow color for dark areas (#282828).
113-
/// </summary>
114-
public static Color ShadowDarkColor { get; } = Color.FromArgb(40, 40, 40); // #282828
115-
116-
/// <summary>
117-
/// Shadow color for mid-tone areas (#3C3C3C).
118-
/// </summary>
119-
public static Color ShadowColor { get; } = Color.FromArgb(60, 60, 60); // #3C3C3C
120-
121-
/// <summary>
122-
/// Highlight color for button edges (#6E6E6E).
123-
/// </summary>
124-
public static Color HighlightColor { get; } = Color.FromArgb(110, 110, 110); // #6E6E6E
125-
126-
/// <summary>
127-
/// Bright highlight color for button edges (#828282).
128-
/// </summary>
129-
public static Color HighlightBrightColor { get; } = Color.FromArgb(130, 130, 130); // #828282
130-
131-
/// <summary>
132-
/// Disabled border dark color (#2D2D2D).
133-
/// </summary>
134-
public static Color DisabledBorderDarkColor { get; } = Color.FromArgb(45, 45, 45); // #2D2D2D
135-
136-
/// <summary>
137-
/// Disabled border light color (#373737).
138-
/// </summary>
139-
public static Color DisabledBorderLightColor { get; } = Color.FromArgb(55, 55, 55); // #373737
140-
141-
/// <summary>
142-
/// Disabled border mid color (#323232).
143-
/// </summary>
144-
public static Color DisabledBorderMidColor { get; } = Color.FromArgb(50, 50, 50); // #323232
145-
}
7+
/// Cache of colors for different button states.
8+
/// </summary>
9+
internal static class DarkModeButtonColors
10+
{
11+
// Normal Button (non-default)
12+
13+
/// <summary>
14+
/// Button background color for normal state (#2B2B2B).
15+
/// </summary>
16+
public static Color NormalBackgroundColor => Color.FromArgb(43, 43, 43); // #2B2B2B
17+
18+
/// <summary>
19+
/// Button background color for hover state (#3B3B3B).
20+
/// </summary>
21+
public static Color HoverBackgroundColor => Color.FromArgb(59, 59, 59); // #3B3B3B
22+
23+
/// <summary>
24+
/// Button background color for pressed state (#4B4B4B).
25+
/// </summary>
26+
public static Color PressedBackgroundColor => Color.FromArgb(75, 75, 75); // #4B4B4B
27+
28+
/// <summary>
29+
/// Button background color for disabled state (#252525).
30+
/// </summary>
31+
public static Color DisabledBackgroundColor => Color.FromArgb(37, 37, 37); // #252525
32+
33+
// Default Button
34+
35+
/// <summary>
36+
/// Default button background color (#2B2B2B).
37+
/// </summary>
38+
public static Color DefaultBackgroundColor => NormalBackgroundColor; // #2B2B2B
39+
40+
/// <summary>
41+
/// Default button hover background color (#3B3B3B).
42+
/// </summary>
43+
public static Color DefaultHoverBackgroundColor => HoverBackgroundColor; // #3B3B3B
44+
45+
/// <summary>
46+
/// Default button pressed background color (#4B4B4B).
47+
/// </summary>
48+
public static Color DefaultPressedBackgroundColor => PressedBackgroundColor; // #4B4B4B
49+
50+
/// <summary>
51+
/// Default button disabled background color (#252525).
52+
/// </summary>
53+
public static Color DefaultDisabledBackgroundColor => DisabledBackgroundColor; // #252525
54+
55+
// Text Colors
56+
57+
/// <summary>
58+
/// Normal text color (#E0E0E0).
59+
/// </summary>
60+
public static Color NormalTextColor => Color.FromArgb(224, 224, 224); // #E0E0E0
61+
62+
/// <summary>
63+
/// Default button text color (#FFFFFF).
64+
/// </summary>
65+
public static Color DefaultTextColor => Color.White; // #FFFFFF
66+
67+
/// <summary>
68+
/// Disabled text color (#606060, ~40% opacity).
69+
/// </summary>
70+
public static Color DisabledTextColor => Color.FromArgb(96, 96, 96); // #606060
71+
72+
/// <summary>
73+
/// Gets the single border color for a button in dark mode (#969696).
74+
/// </summary>
75+
public static Color SingleBorderColor => Color.FromArgb(150, 150, 150); // #969696
76+
77+
/// <summary>
78+
/// Gets the single border color for a default button in dark mode (#D2D2D2).
79+
/// </summary>
80+
public static Color DefaultSingleBorderColor => Color.FromArgb(210, 210, 210); // #D2D2D2
81+
82+
/// <summary>
83+
/// Gets the single border color for a pressed button in dark mode (#DCDCDC).
84+
/// </summary>
85+
public static Color PressedSingleBorderColor => Color.FromArgb(220, 220, 220); // #DCDCDC
86+
87+
/// <summary>
88+
/// Button top-left border color (#555555).
89+
/// </summary>
90+
public static Color TopLeftBorderColor => Color.FromArgb(85, 85, 85); // #555555
91+
92+
/// <summary>
93+
/// Button bottom-right border color (#222222).
94+
/// </summary>
95+
public static Color BottomRightBorderColor => Color.FromArgb(34, 34, 34); // #222222
96+
97+
// Focus Colors
98+
99+
/// <summary>
100+
/// Focus indicator color (#F0F0F0).
101+
/// </summary>
102+
public static Color FocusIndicatorColor => Color.FromArgb(240, 240, 240); // #F0F0F0
103+
104+
/// <summary>
105+
/// Default button focus indicator color (#FFFFFF).
106+
/// </summary>
107+
public static Color DefaultFocusIndicatorColor => Color.White; // #FFFFFF
108+
109+
// Shadow and Highlight Colors for 3D effects
110+
111+
/// <summary>
112+
/// Shadow color for dark areas (#282828).
113+
/// </summary>
114+
public static Color ShadowDarkColor { get; } = Color.FromArgb(40, 40, 40); // #282828
115+
116+
/// <summary>
117+
/// Shadow color for mid-tone areas (#3C3C3C).
118+
/// </summary>
119+
public static Color ShadowColor { get; } = Color.FromArgb(60, 60, 60); // #3C3C3C
120+
121+
/// <summary>
122+
/// Highlight color for button edges (#6E6E6E).
123+
/// </summary>
124+
public static Color HighlightColor { get; } = Color.FromArgb(110, 110, 110); // #6E6E6E
125+
126+
/// <summary>
127+
/// Bright highlight color for button edges (#828282).
128+
/// </summary>
129+
public static Color HighlightBrightColor { get; } = Color.FromArgb(130, 130, 130); // #828282
130+
131+
/// <summary>
132+
/// Disabled border dark color (#2D2D2D).
133+
/// </summary>
134+
public static Color DisabledBorderDarkColor { get; } = Color.FromArgb(45, 45, 45); // #2D2D2D
135+
136+
/// <summary>
137+
/// Disabled border light color (#373737).
138+
/// </summary>
139+
public static Color DisabledBorderLightColor { get; } = Color.FromArgb(55, 55, 55); // #373737
140+
141+
/// <summary>
142+
/// Disabled border mid color (#323232).
143+
/// </summary>
144+
public static Color DisabledBorderMidColor { get; } = Color.FromArgb(50, 50, 50); // #323232
145+
}

src/System.Windows.Forms/System/Windows/Forms/Controls/TabControl/TabControl.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2022,6 +2022,7 @@ private unsafe void WmTabBaseReLayout()
20222022

20232023
// Remove other TabBaseReLayout messages from the message queue
20242024
MSG msg = default;
2025+
20252026
while (PInvokeCore.PeekMessage(
20262027
&msg,
20272028
this,

src/System.Windows.Forms/System/Windows/Forms/MDI/MDIClient.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,15 @@ public sealed partial class MdiClient : Control
2929
public MdiClient() : base()
3030
{
3131
SetStyle(ControlStyles.Selectable, false);
32-
BackColor = SystemColors.AppWorkspace;
33-
Dock = DockStyle.Fill;
3432
}
3533

3634
#pragma warning disable WFO5001 // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed.
3735
protected override void InitializeControl(int deviceDpi)
3836
{
3937
base.InitializeControl(deviceDpi);
4038
SetStyle(ControlStyles.ApplyThemingImplicitly, true);
39+
BackColor = SystemColors.AppWorkspace;
40+
Dock = DockStyle.Fill;
4141
}
4242
#pragma warning restore WFO5001 // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed.
4343

0 commit comments

Comments
 (0)