From f40e9bffc4088f739a852b4dcf67b44ae6e8da25 Mon Sep 17 00:00:00 2001 From: Sathish S <125439103+Sathish-087@users.noreply.github.com> Date: Mon, 8 Jun 2026 10:16:03 +0530 Subject: [PATCH 1/2] Added fix for issue 9958 Added logic to determine foreground color based on the form's ForeColor property. --- .../Windows/Forms/Controls/GroupBox/GroupBox.cs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/System.Windows.Forms/System/Windows/Forms/Controls/GroupBox/GroupBox.cs b/src/System.Windows.Forms/System/Windows/Forms/Controls/GroupBox/GroupBox.cs index c4f606b8446..944bf9a7d50 100644 --- a/src/System.Windows.Forms/System/Windows/Forms/Controls/GroupBox/GroupBox.cs +++ b/src/System.Windows.Forms/System/Windows/Forms/Controls/GroupBox/GroupBox.cs @@ -421,6 +421,9 @@ protected override void OnPaint(PaintEventArgs e) textFlags |= (TextFormatFlags.Right | TextFormatFlags.RightToLeft); } + var form = FindForm(); + Color foreColor = form is not null ? form.ForeColor : SystemColors.ControlText; + // We only pass in the text color if it is explicitly set, else we let the renderer use the color // specified by the theme. This is a temporary workaround till we find a good solution for the // "default theme color" issue. @@ -438,6 +441,17 @@ protected override void OnPaint(PaintEventArgs e) textFlags, gbState); } + else if (!ShouldSerializeForeColor() && foreColor != SystemColors.ControlText) + { + GroupBoxRenderer.DrawGroupBox( + e, + new Rectangle(0, 0, Width, Height), + Text, + Font, + foreColor, + textFlags, + gbState); + } else { GroupBoxRenderer.DrawGroupBox( From e90871a542974c958275798de6dcdb01ae55f307 Mon Sep 17 00:00:00 2001 From: Sathish S <125439103+Sathish-087@users.noreply.github.com> Date: Mon, 8 Jun 2026 13:30:23 +0530 Subject: [PATCH 2/2] Updated the review changes --- .../Forms/Controls/GroupBox/GroupBox.cs | 30 +++++++++---------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/src/System.Windows.Forms/System/Windows/Forms/Controls/GroupBox/GroupBox.cs b/src/System.Windows.Forms/System/Windows/Forms/Controls/GroupBox/GroupBox.cs index 944bf9a7d50..9f2a64f3c9c 100644 --- a/src/System.Windows.Forms/System/Windows/Forms/Controls/GroupBox/GroupBox.cs +++ b/src/System.Windows.Forms/System/Windows/Forms/Controls/GroupBox/GroupBox.cs @@ -421,9 +421,6 @@ protected override void OnPaint(PaintEventArgs e) textFlags |= (TextFormatFlags.Right | TextFormatFlags.RightToLeft); } - var form = FindForm(); - Color foreColor = form is not null ? form.ForeColor : SystemColors.ControlText; - // We only pass in the text color if it is explicitly set, else we let the renderer use the color // specified by the theme. This is a temporary workaround till we find a good solution for the // "default theme color" issue. @@ -441,26 +438,29 @@ protected override void OnPaint(PaintEventArgs e) textFlags, gbState); } - else if (!ShouldSerializeForeColor() && foreColor != SystemColors.ControlText) - { - GroupBoxRenderer.DrawGroupBox( - e, - new Rectangle(0, 0, Width, Height), - Text, - Font, - foreColor, - textFlags, - gbState); - } else { - GroupBoxRenderer.DrawGroupBox( + if (FindForm() is Form form && form.ForeColor != SystemColors.ControlText) + { + GroupBoxRenderer.DrawGroupBox( + e, + new Rectangle(0, 0, Width, Height), + Text, + Font, + form.ForeColor, + textFlags, + gbState); + } + else + { + GroupBoxRenderer.DrawGroupBox( e, new Rectangle(0, 0, Width, Height), Text, Font, textFlags, gbState); + } } }