Skip to content
Open
Changes from 2 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 @@ -440,13 +440,27 @@ protected override void OnPaint(PaintEventArgs e)
}
else
{
GroupBoxRenderer.DrawGroupBox(
if (FindForm() is Form form && form.ForeColor != SystemColors.ControlText)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Added three unit tests covering: ambient ForeColor inherited from a Form, ambient ForeColor inherited from an intermediate Panel (the exact scenario FindForm() would have missed), and explicit ForeColor taking precedence over any ambient value.

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.

  1. The fix uses FindForm() which jumps directly to the top-level Form. If the GroupBox is inside a Panel or UserControl that has a custom ForeColor, the ambient color from that intermediate parent is ignored.

    WinForms ambient property inheritance walks the full parent chain. this.ForeColor already returns the correct inherited value from any ancestor. A simpler and more correct fix would be to check whether the inherited ForeColor differs from the default

  2. form.ForeColor != SystemColors.ControlText assumes the default form ForeColor is always SystemColors.ControlText. If a high-contrast theme or custom Windows theme changes the default, this comparison could produce incorrect results

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Thank you for the feedback! Both points have been addressed:

  • Replaced FindForm() with this.ForeColor, which already walks the full parent chain via WinForms ambient property inheritance — so intermediate parents with a custom ForeColor are correctly respected.
  • Replaced the form.ForeColor != SystemColors.ControlText comparison with ForeColor != DefaultForeColor. DefaultForeColor is theme-aware and resolves correctly under high-contrast and custom Windows themes.

{
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);
}

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Replaced FindForm() with this.ForeColor, which already walks the full parent chain via WinForms ambient property inheritance — so intermediate parents with a custom ForeColor are correctly respected.

Comment thread
LeafShi1 marked this conversation as resolved.
Outdated
}
}

Expand Down
Loading