Skip to content

Commit 69aba2d

Browse files
Prepare ButtonBase for DarkMode rendering.
1 parent 254eeac commit 69aba2d

File tree

1 file changed

+37
-22
lines changed
  • src/System.Windows.Forms/System/Windows/Forms/Controls/Buttons

1 file changed

+37
-22
lines changed

src/System.Windows.Forms/System/Windows/Forms/Controls/Buttons/ButtonBase.cs

+37-22
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,6 @@ protected ButtonBase()
7777
SetExtendedState(ExtendedStates.UserPreferredSizeCache, true);
7878

7979
SetStyle(ControlStyles.UserMouse | ControlStyles.UserPaint, OwnerDraw);
80-
81-
#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.
82-
SetStyle(ControlStyles.ApplyThemingImplicitly, true);
83-
#pragma warning restore WFO5001
84-
8580
SetFlag(FlagUseMnemonic, true);
8681
SetFlag(FlagShowToolTip, false);
8782
}
@@ -617,7 +612,11 @@ internal virtual Rectangle OverChangeRectangle
617612
}
618613
}
619614

620-
internal bool OwnerDraw => FlatStyle != FlatStyle.System;
615+
#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.
616+
internal bool OwnerDraw =>
617+
(FlatStyle != FlatStyle.System)
618+
|| Application.IsDarkModeEnabled;
619+
#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.
621620

622621
bool? ICommandBindingTargetProvider.PreviousEnabledStatus { get; set; }
623622

@@ -965,27 +964,37 @@ internal ButtonBaseAdapter Adapter
965964
{
966965
get
967966
{
968-
if (_adapter is null || FlatStyle != _cachedAdapterType)
967+
#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.
968+
if (_adapter is null
969+
|| FlatStyle != _cachedAdapterType)
969970
{
970-
switch (FlatStyle)
971+
if (Application.IsDarkModeEnabled)
971972
{
972-
case FlatStyle.Standard:
973-
_adapter = CreateStandardAdapter();
974-
break;
975-
case FlatStyle.Popup:
976-
_adapter = CreatePopupAdapter();
977-
break;
978-
case FlatStyle.Flat:
979-
_adapter = CreateFlatAdapter();
980-
;
981-
break;
982-
default:
983-
Debug.Fail($"Unsupported FlatStyle: \"{FlatStyle}\"");
984-
break;
973+
_adapter = CreateDarkModeAdapter();
985974
}
975+
else
976+
{
977+
switch (FlatStyle)
978+
{
979+
case FlatStyle.Standard:
980+
_adapter = CreateStandardAdapter();
981+
break;
982+
case FlatStyle.Popup:
983+
_adapter = CreatePopupAdapter();
984+
break;
985+
case FlatStyle.Flat:
986+
_adapter = CreateFlatAdapter();
987+
;
988+
break;
989+
default:
990+
Debug.Fail($"Unsupported FlatStyle: \"{FlatStyle}\"");
991+
break;
992+
}
986993

987-
_cachedAdapterType = FlatStyle;
994+
_cachedAdapterType = FlatStyle;
995+
}
988996
}
997+
#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.
989998

990999
return _adapter;
9911000
}
@@ -1009,6 +1018,12 @@ internal virtual ButtonBaseAdapter CreateStandardAdapter()
10091018
return null;
10101019
}
10111020

1021+
internal virtual ButtonBaseAdapter CreateDarkModeAdapter()
1022+
{
1023+
Debug.Fail("Derived classes need to provide a meaningful implementation.");
1024+
return null;
1025+
}
1026+
10121027
internal virtual StringFormat CreateStringFormat()
10131028
{
10141029
if (Adapter is null)

0 commit comments

Comments
 (0)