Skip to content

Commit

Permalink
* Enable GroupBox...
Browse files Browse the repository at this point in the history
* Enable PropertyGrid
* Fix some code formatting issues
* Try easy fixes for Calendar.
  • Loading branch information
KlausLoeffelmann committed Mar 18, 2024
1 parent c080315 commit 3701417
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 57 deletions.
79 changes: 39 additions & 40 deletions src/System.Windows.Forms/src/System/Windows/Forms/Control.cs
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,6 @@ private protected void TraceCanProcessMnemonic()

private static bool s_needToLoadComCtl = true;
private static readonly int s_darkModeProperty = PropertyStore.CreateKey();
private static readonly int s_isDarkModeEnabledProperty = PropertyStore.CreateKey();

// This switch determines the default text rendering engine to use by some controls that support switching rendering engine.
// CheckedListBox, PropertyGrid, GroupBox, Label and LinkLabel, and ButtonBase controls.
Expand Down Expand Up @@ -7840,50 +7839,50 @@ protected virtual void OnHandleCreated(EventArgs e)
{
if (this is

// Controls with four levels of inheritance, sorted alphabetically by type name
DomainUpDown // Inherits from UpDownBase, ContainerControl, ScrollableControl, Control
or NumericUpDown // Inherits from UpDownBase, ContainerControl, ScrollableControl, Control
// Controls with 4 levels of inheritance, sorted alphabetically by type name
DomainUpDown // Inherits from UpDownBase, ContainerControl, ScrollableControl, Control
or NumericUpDown // Inherits from UpDownBase, ContainerControl, ScrollableControl, Control

// Controls with three levels of inheritance, sorted alphabetically by type name
or CheckedListBox // Inherits from ListBox, ListControl, Control
or Form // Excluded - too invasive.
or FlowLayoutPanel // Inherits from Panel, ScrollableControl, Control
or SplitContainer // Inherits from ContainerControl, ScrollableControl, Control
or TabPage // Inherits from Panel, ScrollableControl, Control
or TableLayoutPanel // Inherits from Panel, ScrollableControl, Control
// Controls with 3 levels of inheritance, sorted alphabetically by type name
or CheckedListBox // Inherits from ListBox, ListControl, Control
or Form // Excluded - too invasive.
or FlowLayoutPanel // Inherits from Panel, ScrollableControl, Control
or SplitContainer // Inherits from ContainerControl, ScrollableControl, Control
or TabPage // Inherits from Panel, ScrollableControl, Control
or TableLayoutPanel // Inherits from Panel, ScrollableControl, Control

// Controls with 2 levels of inheritance, sorted alphabetically by type name
// or ComboBox // Excluded - directly handled.
or ListBox // Inherits from ListControl, Control

or Button // Inherits from ButtonBase, Control
or CheckBox // Inherits from ButtonBase, Control
or MaskedTextBox // Inherits from TextBoxBase, Control
or Panel // Inherits from ScrollableControl, Control
or RadioButton // Inherits from ButtonBase, Control
or RichTextBox // Inherits from TextBoxBase, Control
or TextBox // Inherits from TextBoxBase, Control
// or ComboBox // Excluded - directly handled.
or ListBox // Inherits from ListControl, Control

or Button // Inherits from ButtonBase, Control
or CheckBox // Inherits from ButtonBase, Control
or MaskedTextBox // Inherits from TextBoxBase, Control
or Panel // Inherits from ScrollableControl, Control
or RadioButton // Inherits from ButtonBase, Control
or RichTextBox // Inherits from TextBoxBase, Control
or TextBox // Inherits from TextBoxBase, Control
or HScrollBar // Inherits from ScrollBar, Control
or VScrollBar // Inherits from ScrollBar, Control

// Base classes and controls with direct inheritance from Control, sorted alphabetically by type name
// or ButtonBase // Excluded - probably too invasive.
or DateTimePicker // Inherits from Control
or GroupBox // Inherits from Control directly, but behaves like a container
or HScrollBar // Inherits from ScrollBar, Control
or Label // Inherits from Control
or LinkLabel // Inherits from Label, Control
// or ListView // Excluded - directly handled.
or MonthCalendar // Inherits from Control
or PictureBox // Inherits from Control
or ProgressBar // Inherits from Control
// or ScrollableControl // Excluded - probably too invasive.
// or TextBoxBase // Excluded - probably too invasive.
or TrackBar // Inherits from Control
or TreeView // Inherits from Control
// or UpDownBase // Excluded - probably too invasive.
or VScrollBar // Inherits from ScrollBar, Control

// Base class for all UI controls in WinForms
or Control)
or ButtonBase // Inherits from Control
or DateTimePicker // Inherits from Control
// or GroupBox // Inherits from Control directly, but behaves like a container
or Label // Inherits from Control
or LinkLabel // Inherits from Label, Control
// or ListView // Excluded - directly handled.
or MonthCalendar // Inherits from Control
or PictureBox // Inherits from Control
or ProgressBar // Inherits from Control
or ScrollableControl // Inherits from Control
or TextBoxBase // Excluded - probably too invasive.
or TrackBar // Inherits from Control
or TreeView // Inherits from Control
or UpDownBase) // Inherits from Control

// Base class for all UI controls in WinForms
// or Control // Excluded.
{
_ = PInvoke.SetWindowTheme(HWND, "DarkMode_Explorer", null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public DateTimePicker() : base()
[EditorBrowsable(EditorBrowsableState.Never)]
public override Color BackColor
{
get => ShouldSerializeBackColor() ? base.BackColor : Application.SystemColors.Window;
get => ShouldSerializeBackColor() || IsDarkModeEnabled ? base.BackColor : Application.SystemColors.Window;
set => base.BackColor = value;
}

Expand Down Expand Up @@ -488,7 +488,7 @@ public LeftRightAlignment DropDownAlign
[EditorBrowsable(EditorBrowsableState.Never)]
public override Color ForeColor
{
get => ShouldSerializeForeColor() ? base.ForeColor : Application.SystemColors.WindowText;
get => ShouldSerializeForeColor() || IsDarkModeEnabled ? base.ForeColor : Application.SystemColors.WindowText;
set => base.ForeColor = value;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -397,8 +397,8 @@ protected override void OnPaint(PaintEventArgs e)
{
// BACKCOMPAT requirement:
//
// Why the Height/Width < 10 check? This is because uxtheme doesn't seem to handle those cases similar to
// what we do for the non-themed case, so if someone is using the groupbox as a separator, their app will
// Why the Height/Width < 10 check? This is because Ux-theme doesn't seem to handle those cases similar to
// what we do for the non-themed case, so if someone is using the GroupBox as a separator, their app will
// look weird in .NET Framework 2.0. We render the old way in these cases.

if (!Application.RenderWithVisualStyles || Width < 10 || Height < 10)
Expand All @@ -424,15 +424,15 @@ protected override void OnPaint(PaintEventArgs e)
// 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.
if (ShouldSerializeForeColor() || Enabled == false)
if (ShouldSerializeForeColor() || IsDarkModeEnabled || Enabled == false)
{
Color textcolor = Enabled ? ForeColor : TextRenderer.DisabledTextColor(BackColor);
Color textColor = Enabled ? ForeColor : TextRenderer.DisabledTextColor(BackColor);
GroupBoxRenderer.DrawGroupBox(
e,
new Rectangle(0, 0, Width, Height),
Text,
Font,
textcolor,
textColor,
textFlags,
gbState);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4613,9 +4613,6 @@ protected override void OnHandleCreated(EventArgs e)
PInvoke.SendMessage(this, PInvoke.CCM_SETVERSION, (WPARAM)5);
}

UpdateExtendedStyles();
RealizeProperties();

if (IsDarkModeEnabled)
{
_ = PInvoke.SetWindowTheme(HWND, "DarkMode_Explorer", null);
Expand All @@ -4625,6 +4622,9 @@ protected override void OnHandleCreated(EventArgs e)
PInvoke.SetWindowTheme(columnHeaderHandle, "DarkMode_ItemsView", null);
}

UpdateExtendedStyles();
RealizeProperties();

PInvoke.SendMessage(this, PInvoke.LVM_SETBKCOLOR, (WPARAM)0, (LPARAM)BackColor);
PInvoke.SendMessage(this, PInvoke.LVM_SETTEXTCOLOR, (WPARAM)0, (LPARAM)ForeColor);

Expand Down Expand Up @@ -6032,9 +6032,7 @@ private unsafe bool WmNotify(ref Message m)

else if (nmlvcd->nmcd.dwDrawStage == NMCUSTOMDRAW_DRAW_STAGE.CDDS_ITEMPREPAINT)
{
// We're just setting the text color, but we do not adapt the text (fore) color,
// instead we stick to the theming settings...
PInvoke.SetTextColor(nmlvcd->nmcd.hdc, Application.SystemColors.WindowText);
PInvoke.SetTextColor(nmlvcd->nmcd.hdc, ForeColor);

// ...and then just let the default handling play out.
m.ResultInternal = (LRESULT)(nint)PInvoke.CDRF_DODEFAULT;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public partial class MonthCalendar : Control
/// <summary>
/// This is the arbitrary number of pixels that the Win32 control
/// inserts between calendars vertically, regardless of font.
/// From comctl32 MonthCalendar sources CALBORDER.
/// From ComCtl32 MonthCalendar sources CALBORDER.
/// </summary>
private const int InsertHeightSize = 6;

Expand Down Expand Up @@ -193,7 +193,7 @@ public override Color BackColor
{
get
{
if (ShouldSerializeBackColor())
if (ShouldSerializeBackColor() || IsDarkModeEnabled)
{
return base.BackColor;
}
Expand Down Expand Up @@ -407,7 +407,7 @@ public override Color ForeColor
{
get
{
if (ShouldSerializeForeColor())
if (ShouldSerializeForeColor() || IsDarkModeEnabled)
{
return base.ForeColor;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,11 @@ public partial class PropertyGrid : ContainerControl, IComPropertyBrowser, IProp
private object[]? _selectedObjects;

private int _paintFrozen;
private Color _lineColor = SystemInformation.HighContrast ? Application.SystemColors.ControlDarkDark : Application.SystemColors.InactiveBorder;

private Color _lineColor = SystemInformation.HighContrast
? Application.SystemColors.ControlDarkDark
: Application.SystemColors.InactiveBorder;

private Color _categoryForegroundColor = Application.SystemColors.ControlText;
private Color _categorySplitterColor = Application.SystemColors.Control;
private Color _viewBorderColor = Application.SystemColors.ControlDark;
Expand Down Expand Up @@ -2537,6 +2541,11 @@ protected override void OnFontChanged(EventArgs e)
protected override void OnHandleCreated(EventArgs e)
{
base.OnHandleCreated(e);

// Making sure, the _toolBar BackColor gets updated when the
// default BackColor is not the typical light-theme one.
BackColor = BackColor;

OnLayoutInternal(dividerOnly: false);
TypeDescriptor.Refreshed += OnTypeDescriptorRefreshed;
if (_selectedObjects is not null && _selectedObjects.Length > 0)
Expand Down

0 comments on commit 3701417

Please sign in to comment.