Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable DarkMode Theming #10985

Closed
wants to merge 71 commits into from
Closed
Changes from 1 commit
Commits
Show all changes
71 commits
Select commit Hold shift + click to select a range
27213f8
First draft of DarkMode implementation.
KlausLoeffelmann Aug 23, 2022
fde619f
First draft of Darkmode for ToolStrips.
KlausLoeffelmann Aug 30, 2022
5e08a22
Fix merge issues.
KlausLoeffelmann Jul 17, 2023
36f812e
Implement Form title bar coloring and
KlausLoeffelmann Mar 2, 2024
661e547
Implement DarkMode color table and replace SystemColors by dynamic co…
KlausLoeffelmann Mar 3, 2024
1694d56
Correct Formatting/Merge issues.
KlausLoeffelmann Mar 4, 2024
c768e59
Fix rendering ListView ColumnHeaders in wrong text color in dark mode.
KlausLoeffelmann Mar 3, 2024
63c880d
Added more XML comments and refactored the IsDarkModeEnabled logic a …
KlausLoeffelmann Mar 5, 2024
4fd84b6
Update unshipped API list.
KlausLoeffelmann Mar 5, 2024
a0842c0
* Enable GroupBox...
KlausLoeffelmann Mar 6, 2024
2fdfb2d
Handle DarkMode ProgressBar.
KlausLoeffelmann Mar 18, 2024
0074857
Ensure that IsDarkModeEnabled always returns a valid result.
KlausLoeffelmann Mar 26, 2024
f581657
Fixing merge issues.
KlausLoeffelmann Jun 22, 2024
63e5c87
Introduce DefaultVisualStyleMode.
KlausLoeffelmann Jun 22, 2024
3397820
Introduce VisualStylesMode as ambient property on Control.
KlausLoeffelmann Jun 23, 2024
3eec957
Update XML comments and Description attribute resources for new prope…
KlausLoeffelmann Jun 23, 2024
38bf198
Introduce VisualStylesModeCore.
KlausLoeffelmann Jun 24, 2024
25b1421
Revert "Introduce VisualStylesModeCore."
KlausLoeffelmann Jun 24, 2024
cdef2b8
Fix usage of DefaultVisualStylesMode.
KlausLoeffelmann Jun 24, 2024
d19f8b9
Update PublicAPI.
KlausLoeffelmann Jun 24, 2024
c1c900f
First implementation of setting new NCClient area in TextBox for taki…
KlausLoeffelmann Jun 24, 2024
837ab4f
Add better VisualStylesMode validation.
KlausLoeffelmann Jun 25, 2024
d29f2b4
Rename Application.SystemColors to Application.ApplicationColors.
KlausLoeffelmann Jun 25, 2024
0e3825b
Minimize exceptions for control dark mode theming.
KlausLoeffelmann Jun 25, 2024
6ac99e0
First draft of non-client painting of TextBoxBase adorners.
KlausLoeffelmann Jun 26, 2024
92ccc9e
Update logic for vertically aligning a single line TextBox and taking…
KlausLoeffelmann Jun 27, 2024
4737ad9
Update TextBox adorner rendering.
KlausLoeffelmann Jun 29, 2024
cfbac62
Address additional property combination for rendering.
KlausLoeffelmann Jul 8, 2024
8d23b76
Add first version of modern CheckBox renderer.
KlausLoeffelmann Jul 9, 2024
e4aaa46
Fix some renderer issues.
KlausLoeffelmann Jul 9, 2024
b307cb5
Add ToggleSwitch animation.
KlausLoeffelmann Jul 11, 2024
ffa5a9a
Introduce Experimental feature WFO9000 - VisualStylesMode.
KlausLoeffelmann Jul 12, 2024
5e9d6e0
Introduce Experimental Feature WFO9001 - DarkMode.
KlausLoeffelmann Jul 12, 2024
fd0be10
Edge case bugfixing:
KlausLoeffelmann Jul 12, 2024
bab5ef8
Fix CheckBox ToggleSwitch animation issue.
KlausLoeffelmann Jul 15, 2024
2ce0560
Introduce APIs for customizing TextBoxBase adorner painting.
KlausLoeffelmann Jul 16, 2024
71fced4
Address freview feedback.
KlausLoeffelmann Jul 17, 2024
8f285ad
Fix merge issue.
KlausLoeffelmann Jul 25, 2024
042fef3
Refactored out instance DarkMode from Control, introduces ControlSyst…
KlausLoeffelmann Jul 21, 2024
9b42818
Fix animation control renderer issue.
KlausLoeffelmann Jul 22, 2024
51826ea
Improve theming handling.
KlausLoeffelmann Jul 23, 2024
3798c5f
Refactor VisualStyleMode.
KlausLoeffelmann Jul 23, 2024
35c304f
Inplement ControlStyles.ApplyThemingImplicitly.
KlausLoeffelmann Jul 25, 2024
c7f8a29
Refactor to reflect results from latest API naming discussion.
KlausLoeffelmann Jul 26, 2024
28bab8f
Fix UpDownBase and dark professional colors.
KlausLoeffelmann Jul 28, 2024
8a46567
Refactor AnimatedControlRenderer to include additional use cases.
KlausLoeffelmann Jul 29, 2024
3740f10
Fix dark mode MenueItem rendering.
KlausLoeffelmann Jul 29, 2024
57431f2
Revert cc99a677.
KlausLoeffelmann Jul 29, 2024
ef8412b
Add DarkMode and modern VisualStyles to the Visual Basic App Framework.
KlausLoeffelmann Jul 30, 2024
42ed403
Convert Window control methods into bindable properties.
KlausLoeffelmann Jul 31, 2024
826a6c5
Refactor SystemColors to use UseAlternativeColorSet.
KlausLoeffelmann Jul 31, 2024
e841c9f
Fix issues with SystemColors and UseAlternativeColorSet.
KlausLoeffelmann Aug 1, 2024
cab1ccf
Refactor dark mode changes based on DiagnosticIDs refactoring.
KlausLoeffelmann Aug 1, 2024
39fd560
Update Multiline TextBox, Scrollbar & Focus Painting.
KlausLoeffelmann Aug 3, 2024
17cb0d4
Address TextBoxBase flicker issues by double-buffering NcPainting.
KlausLoeffelmann Aug 3, 2024
c261586
Address review feedback.
KlausLoeffelmann Aug 4, 2024
2acce90
Fix a few Graphics scoping hick-ups.
KlausLoeffelmann Aug 4, 2024
2cfe7b9
Eliminate redundant Pragma warning disables.
KlausLoeffelmann Aug 4, 2024
4e7ac23
Amend VB App Framework infrastructure props attributes.
KlausLoeffelmann Aug 4, 2024
bef5954
Perform general PR clean up.
KlausLoeffelmann Aug 4, 2024
9832595
Fix some VisualStyleMode refactoring issues.
KlausLoeffelmann Aug 4, 2024
4a9a108
Fix ref struct issue in release builds.
KlausLoeffelmann Aug 4, 2024
3c5681c
Update TextBoxBase style default settings.
KlausLoeffelmann Aug 5, 2024
2df4dbb
Add enum range checks, fix minor issues.
KlausLoeffelmann Aug 6, 2024
c61d0d3
Revert comments mentioning Application.SystemColors.
KlausLoeffelmann Aug 6, 2024
3191e93
Address more review feedback.
KlausLoeffelmann Aug 6, 2024
d43855a
Fix CTI backwards compatibility test issues.
KlausLoeffelmann Aug 7, 2024
fc8b256
Fix ExperimentalAttrinute url const.
KlausLoeffelmann Aug 8, 2024
7f7c0d0
Address additional feedback review.
KlausLoeffelmann Aug 8, 2024
bace995
Fix backwards compat issue in Application.RenderWithVisualStyles.
KlausLoeffelmann Aug 8, 2024
cf32e9c
Fix some CTI found issues around the new form border attributes APIs.
KlausLoeffelmann Aug 9, 2024
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
82 changes: 19 additions & 63 deletions src/System.Windows.Forms/src/System/Windows/Forms/Form.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,6 @@ public partial class Form : ContainerControl

private static readonly int s_propOpacity = PropertyStore.CreateKey();
private static readonly int s_propTransparencyKey = PropertyStore.CreateKey();
private static readonly int s_propFormBorderColor = PropertyStore.CreateKey();
private static readonly int s_propFormCaptionBackColor = PropertyStore.CreateKey();

private static readonly int s_propFormCaptionTextColor = PropertyStore.CreateKey();
private static readonly int s_propFormCornerPreference = PropertyStore.CreateKey();

// Form per instance members
Expand Down Expand Up @@ -2364,6 +2360,15 @@ public FormCornerPreference FormCornerPreference
return;
}

_ = value switch
{
FormCornerPreference.Default => value,
FormCornerPreference.DoNotRound => value,
FormCornerPreference.Round => value,
FormCornerPreference.RoundSmall => value,
_ => throw new ArgumentOutOfRangeException(nameof(value))
};

if (value == FormCornerPreference.Default)
{
Properties.RemoveObject(s_propFormCornerPreference);
Expand Down Expand Up @@ -2425,37 +2430,20 @@ private unsafe void SetFormCornerPreferenceInternal(FormCornerPreference cornerP
[Experimental(DiagnosticIDs.ExperimentalDarkMode, UrlFormat = Application.WinFormsExperimentalUrl)]
public Color FormBorderColor

Choose a reason for hiding this comment

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

How to return to the orignal System default Color with this api?
(DWMWA_COLOR_DEFAULT with value 0xFFFFFFFF)

How to remove 1px border color around Form with this api ?
(DWMWA_COLOR_NONE with value 0xFFFFFFFE)

Copy link
Member Author

Choose a reason for hiding this comment

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

Good catch! I will test and add this to the docs! Nice one - adds real value!

{
get
{
if (Properties.ContainsObject(s_propFormBorderColor))
{
return Properties.GetColor(s_propFormBorderColor);
}
else
{
if (!IsHandleCreated || IsAncestorSiteInDesignMode)
{
return Color.Empty;
}
get => GetFormAttributeColorInternal(DWMWINDOWATTRIBUTE.DWMWA_BORDER_COLOR);

return GetFormAttributeColorInternal(DWMWINDOWATTRIBUTE.DWMWA_BORDER_COLOR);
}
}
set
{
if (value == FormBorderColor)
{
return;
}

if (!IsHandleCreated)
if (IsHandleCreated)
{
Properties.SetColor(s_propFormBorderColor, value);
return;
SetFormAttributeColorInternal(DWMWINDOWATTRIBUTE.DWMWA_BORDER_COLOR, value);
}

Properties.SetColor(s_propFormBorderColor, value);
SetFormAttributeColorInternal(DWMWINDOWATTRIBUTE.DWMWA_BORDER_COLOR, value);
OnFormBorderColorChanged(EventArgs.Empty);
}
}
Expand All @@ -2482,35 +2470,19 @@ protected virtual void OnFormBorderColorChanged(EventArgs e)
[Experimental(DiagnosticIDs.ExperimentalDarkMode, UrlFormat = Application.WinFormsExperimentalUrl)]
public Color FormCaptionBackColor
{
get
{
if (Properties.ContainsObject(s_propFormCaptionBackColor))
{
return Properties.GetColor(s_propFormCaptionBackColor);
}

if (!IsHandleCreated || IsAncestorSiteInDesignMode)
{
return Color.Empty;
}

return GetFormAttributeColorInternal(DWMWINDOWATTRIBUTE.DWMWA_CAPTION_COLOR);
}
get => GetFormAttributeColorInternal(DWMWINDOWATTRIBUTE.DWMWA_CAPTION_COLOR);
set
{
if (value == FormCaptionBackColor)
{
return;
}

if (!IsHandleCreated)
if (IsHandleCreated)
{
Properties.SetColor(s_propFormCaptionBackColor, value);
return;
SetFormAttributeColorInternal(DWMWINDOWATTRIBUTE.DWMWA_CAPTION_COLOR, value);
}

Properties.SetColor(s_propFormCaptionBackColor, value);
SetFormAttributeColorInternal(DWMWINDOWATTRIBUTE.DWMWA_CAPTION_COLOR, value);
OnFormCaptionBackColorChanged(EventArgs.Empty);
}
}
Expand All @@ -2537,35 +2509,19 @@ protected virtual void OnFormCaptionBackColorChanged(EventArgs e)
[Experimental(DiagnosticIDs.ExperimentalDarkMode, UrlFormat = Application.WinFormsExperimentalUrl)]
public Color FormCaptionTextColor
{
get
{
if (Properties.ContainsObject(s_propFormCaptionTextColor))
{
return Properties.GetColor(s_propFormCaptionTextColor);
}

if (!IsHandleCreated || IsAncestorSiteInDesignMode)
{
return Color.Empty;
}

return GetFormAttributeColorInternal(DWMWINDOWATTRIBUTE.DWMWA_TEXT_COLOR);
}
get => GetFormAttributeColorInternal(DWMWINDOWATTRIBUTE.DWMWA_TEXT_COLOR);
set
{
if (value == FormCaptionTextColor)
{
return;
}

if (!IsHandleCreated)
if (IsHandleCreated)
{
Properties.SetColor(s_propFormCaptionTextColor, value);
return;
SetFormAttributeColorInternal(DWMWINDOWATTRIBUTE.DWMWA_TEXT_COLOR, value);
}

Properties.SetColor(s_propFormCaptionTextColor, value);
SetFormAttributeColorInternal(DWMWINDOWATTRIBUTE.DWMWA_TEXT_COLOR, value);
OnFormCaptionTextColorChanged(EventArgs.Empty);
}
}
Expand All @@ -2586,7 +2542,7 @@ private unsafe Color GetFormAttributeColorInternal(DWMWINDOWATTRIBUTE dmwWindowA
{
COLORREF colorRef;

PInvoke.DwmSetWindowAttribute(
PInvoke.DwmGetWindowAttribute(
HWND,
dmwWindowAttribute,
&colorRef,
Expand Down
Loading