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
Show file tree
Hide file tree
Changes from 66 commits
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
3 changes: 2 additions & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,8 @@ dotnet_diagnostic.CA1846.severity = error
# CA2246: Do not assign a symbol and its member in the same statement
dotnet_diagnostic.CA2246.severity = error

# CA1855: Use Span<T>.Clear() instead of Span<T>.Fill()
# CA1855: Use Span<T>
.Clear() instead of Span<T>.Fill()
KlausLoeffelmann marked this conversation as resolved.
Show resolved Hide resolved
dotnet_diagnostic.CA1855.severity = error

# CA1857: The parameter expects a constant for optimal performance
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
<AssemblyName>Microsoft.VisualBasic.Forms</AssemblyName>
<Deterministic>true</Deterministic>
<OptionExplicit>On</OptionExplicit>
<OptionInfer>Off</OptionInfer>
<OptionStrict>On</OptionStrict>
<RootNamespace></RootNamespace>
<LangVersion>Latest</LangVersion>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
' The .NET Foundation licenses this file to you under the MIT license.

Imports System.ComponentModel
Imports System.Diagnostics.CodeAnalysis
Imports System.Drawing
Imports System.Runtime.InteropServices
Imports System.Windows.Forms
Imports System.Windows.Forms.Analyzers.Diagnostics

Namespace Microsoft.VisualBasic.ApplicationServices

Expand All @@ -15,11 +17,21 @@ Namespace Microsoft.VisualBasic.ApplicationServices
Public Class ApplyApplicationDefaultsEventArgs
Inherits EventArgs

#Disable Warning WFO5001
#Disable Warning WFO5000
Friend Sub New(minimumSplashScreenDisplayTime As Integer,
highDpiMode As HighDpiMode)
highDpiMode As HighDpiMode,
colorMode As SystemColorMode,
visualStylesMode As VisualStylesMode)

Me.MinimumSplashScreenDisplayTime = minimumSplashScreenDisplayTime
Me.HighDpiMode = highDpiMode
Me.ColorMode = colorMode
Me.VisualStylesMode = visualStylesMode

End Sub
#Enable Warning WFO5000
#Enable Warning WFO5001

''' <summary>
''' Setting this property inside the event handler causes a new default Font for Forms and UserControls to be set.
Expand All @@ -44,5 +56,20 @@ Namespace Microsoft.VisualBasic.ApplicationServices
''' </remarks>
Public Property HighDpiMode As HighDpiMode

''' <summary>
''' Setting this property inside the event handler determines the <see cref="Application.ColorMode"/> for the application.
''' </summary>
<Experimental(DiagnosticIDs.ExperimentalDarkMode)>
Public Property ColorMode As SystemColorMode

''' <summary>
''' Setting this property inside the event handler determines the <see cref="VisualStylesMode"/> for the application.
''' </summary>
''' <returns></returns>
KlausLoeffelmann marked this conversation as resolved.
Show resolved Hide resolved
<Experimental(DiagnosticIDs.ExperimentalVisualStyles)>
Public Property VisualStylesMode As VisualStylesMode

End Class
#Disable Warning WFO5000
#Disable Warning WFO5001
End Namespace
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@

Imports System.Collections.ObjectModel
Imports System.ComponentModel
Imports System.Diagnostics.CodeAnalysis
Imports System.IO.Pipes
Imports System.Reflection
Imports System.Runtime.CompilerServices
Imports System.Runtime.InteropServices
Imports System.Security
Imports System.Threading
Imports System.Windows.Forms
Imports System.Windows.Forms.Analyzers.Diagnostics

Imports ExUtils = Microsoft.VisualBasic.CompilerServices.ExceptionUtils
Imports VbUtils = Microsoft.VisualBasic.CompilerServices.Utils
Expand Down Expand Up @@ -138,8 +140,19 @@ Namespace Microsoft.VisualBasic.ApplicationServices
' Informs My.Settings whether to save the settings on exit or not.
Private _saveMySettingsOnExit As Boolean

' The HighDpiMode the user picked from the AppDesigner or assigned to the ApplyHighDpiMode's Event.
' The HighDpiMode the user picked from the AppDesigner or assigned to the ApplyApplicationsDefault event.
Private _highDpiMode As HighDpiMode = HighDpiMode.SystemAware
#Disable Warning WFO5001 ' Type is for evaluation purposes only and is subject to change or removal in future updates.
' The ColorMode (Classic/Light, System, Dark) the user assigned to the ApplyApplicationsDefault event.
' Note: We aim to expose this to the App Designer in later runtime/VS versions.
Private _colorMode As SystemColorMode = SystemColorMode.Classic
#Enable Warning WFO5001 ' Type is for evaluation purposes only and is subject to change or removal in future updates.

#Disable Warning WFO5000 ' Type is for evaluation purposes only and is subject to change or removal in future updates.
' The VisualStylesMode (Default is Classic) the user assigned to the ApplyApplicationsDefault event.
' Note: We aim to expose this to the App Designer in later runtime/VS versions.
Private _visualStylesMode As VisualStylesMode = VisualStylesMode.Classic
#Enable Warning WFO5000 ' Type is for evaluation purposes only and is subject to change or removal in future updates.

''' <summary>
''' Occurs when the network availability changes.
Expand Down Expand Up @@ -249,15 +262,15 @@ Namespace Microsoft.VisualBasic.ApplicationServices
RaiseEvent(sender As Object, e As UnhandledExceptionEventArgs)
If _unhandledExceptionHandlers IsNot Nothing Then

' In the case that we throw from the <see cref="UnhandledException"/> handler, we don't want to
' run the <see cref="UnhandledException"/> handler again.
' In the case that we throw from the UnhandledException handler, we don't want to
' run the UnhandledException handler again.
_processingUnhandledExceptionEvent = True

For Each handler As UnhandledExceptionEventHandler In _unhandledExceptionHandlers
handler?.Invoke(sender, e)
Next

' Now that we are out of the <see cref="UnhandledException"/> handler, treat exceptions normally again.
' Now that we are out of the UnhandledException handler, treat exceptions normally again.
_processingUnhandledExceptionEvent = False
End If
End RaiseEvent
Expand Down Expand Up @@ -291,8 +304,8 @@ Namespace Microsoft.VisualBasic.ApplicationServices
If authenticationMode = AuthenticationMode.Windows Then
Try
' Consider: Sadly, a call to: System.Security.SecurityManager.IsGranted(New SecurityPermission(SecurityPermissionFlag.ControlPrincipal))
' Will only check THIS caller so you'll always get TRUE.
' What is needed is a way to get to the value of this on a demand basis.
' Will only check the THIS caller so you'll always get TRUE.
' What we need is a way to get to the value of this on a demand basis.
' So I try/catch instead for now but would rather be able to IF my way around this block.
Thread.CurrentPrincipal = New Principal.WindowsPrincipal(Principal.WindowsIdentity.GetCurrent)
Catch ex As SecurityException
Expand Down Expand Up @@ -349,7 +362,11 @@ Namespace Microsoft.VisualBasic.ApplicationServices
Dim tokenSource As New CancellationTokenSource()
tokenSource.CancelAfter(SECOND_INSTANCE_TIMEOUT)
Try
Dim awaitable As ConfiguredTaskAwaitable = SendSecondInstanceArgsAsync(applicationInstanceID, commandLine, cancellationToken:=tokenSource.Token).ConfigureAwait(False)
Dim awaitable As ConfiguredTaskAwaitable = SendSecondInstanceArgsAsync(
pipeName:=applicationInstanceID,
args:=commandLine,
cancellationToken:=tokenSource.Token).ConfigureAwait(False)

awaitable.GetAwaiter().GetResult()
Catch ex As Exception
Throw New CantStartSingleInstanceException()
Expand Down Expand Up @@ -492,20 +509,27 @@ Namespace Microsoft.VisualBasic.ApplicationServices
' in a derived class and setting `MyBase.MinimumSplashScreenDisplayTime` there.
' We are picking this (probably) changed value up, and pass it to the ApplyDefaultsEvents
' where it could be modified (again). So event wins over Override over default value (2 seconds).
' b) We feed the default HighDpiMode (SystemAware) to the EventArgs. With the introduction of
' the HighDpiMode property, we give Project System the chance to reflect the HighDpiMode
' in the App Designer UI and have it code-generated based on a modified Application.myapp, which
' would result it to be set in the derived constructor. (See the hidden file in the Solution Explorer
' "My Project\Application.myapp\Application.Designer.vb for how those UI-set values get applied.)
' b) We feed the defaults for HighDpiMode, ColorMode, VisualStylesMode to the EventArgs.
' With the introduction of the HighDpiMode property, we changed Project System the chance to reflect
' those default values in the App Designer UI and have it code-generated based on a modified
' Application.myapp, which would result it to be set in the derived constructor.
' (See the hidden file in the Solution Explorer "My Project\Application.myapp\Application.Designer.vb
' for how those UI-set values get applied.)
' Once all this is done, we give the User another chance to change the value by code through
' the ApplyDefaults event.
' Overriding MinimumSplashScreenDisplayTime needs still to keep working!
' Note: Overriding MinimumSplashScreenDisplayTime needs still to keep working!
#Disable Warning WFO5001 ' Type is for evaluation purposes only and is subject to change or removal in future updates.
#Disable Warning WFO5000 ' Type is for evaluation purposes only and is subject to change or removal in future updates.
Dim applicationDefaultsEventArgs As New ApplyApplicationDefaultsEventArgs(
MinimumSplashScreenDisplayTime,
HighDpiMode) With
HighDpiMode,
ColorMode,
VisualStylesMode) With
{
.MinimumSplashScreenDisplayTime = MinimumSplashScreenDisplayTime
}
#Enable Warning WFO5000 ' Type is for evaluation purposes only and is subject to change or removal in future updates.
#Enable Warning WFO5001 ' Type is for evaluation purposes only and is subject to change or removal in future updates.

RaiseEvent ApplyApplicationDefaults(Me, applicationDefaultsEventArgs)

Expand All @@ -521,17 +545,26 @@ Namespace Microsoft.VisualBasic.ApplicationServices

_highDpiMode = applicationDefaultsEventArgs.HighDpiMode

#Disable Warning WFO5001 ' Type is for evaluation purposes only and is subject to change or removal in future updates.
#Disable Warning WFO5000 ' Type is for evaluation purposes only and is subject to change or removal in future updates.

_colorMode = applicationDefaultsEventArgs.ColorMode
_visualStylesMode = applicationDefaultsEventArgs.VisualStylesMode

' Then, it's applying what we got back as HighDpiMode.
Dim dpiSetResult As Boolean = Application.SetHighDpiMode(_highDpiMode)

If dpiSetResult Then
_highDpiMode = Application.HighDpiMode
End If
Debug.Assert(dpiSetResult, "We could net set the HighDpiMode.")

' And finally we take care of EnableVisualStyles.
If _enableVisualStyles Then
Application.EnableVisualStyles()
End If
' Now, let's set VisualStyles and ColorMode:
Application.SetColorMode(_colorMode)
Application.SetDefaultVisualStylesMode(_visualStylesMode)

#Enable Warning WFO5000 ' Type is for evaluation purposes only and is subject to change or removal in future updates.
#Enable Warning WFO5001 ' Type is for evaluation purposes only and is subject to change or removal in future updates.

' We'll handle "/nosplash" for you.
If Not (commandLineArgs.Contains("/nosplash") OrElse Me.CommandLineArgs.Contains("-nosplash")) Then
Expand Down Expand Up @@ -559,7 +592,7 @@ Namespace Microsoft.VisualBasic.ApplicationServices
' It is important not to create the network object until the ExecutionContext has everything on it.
' By now the principal will be on the thread so we can create the network object.
' The timing is important because the network object has an AsyncOperationsManager in it that marshals
' the network changed event to the main thread. The asycnOperationsManager does a CreateOperation()
' the network changed event to the main thread. The asyncOperationsManager does a CreateOperation()
' which makes a copy of the executionContext. That execution context shows up on your thread during
' the callback so I delay creating the network object (and consequently the capturing of the execution context)
' until the principal has been set on the thread. This avoids the problem where My.User isn't set
Expand Down Expand Up @@ -796,6 +829,40 @@ Namespace Microsoft.VisualBasic.ApplicationServices
End Set
End Property

''' <summary>
''' Gets or sets the VisualStylesMode for the Application.
''' </summary>
''' <returns>
''' The <see cref="VisualStylesMode"/> that the application is running in.
''' </returns>
<Experimental(DiagnosticIDs.ExperimentalVisualStyles)>
<EditorBrowsable(EditorBrowsableState.Never)>
Protected Property VisualStylesMode As VisualStylesMode
Get
Return _visualStylesMode
End Get
Set(value As VisualStylesMode)
_visualStylesMode = value
End Set
End Property

''' <summary>
''' Gets or sets the ColorMode for the Application.
''' </summary>
''' <returns>
''' The <see cref="SystemColorMode"/> that the application is running in.
''' </returns>
<Experimental(DiagnosticIDs.ExperimentalDarkMode)>
<EditorBrowsable(EditorBrowsableState.Never)>
Protected Property ColorMode As SystemColorMode
Get
Return _colorMode
End Get
Set(value As SystemColorMode)
_colorMode = value
End Set
End Property

<EditorBrowsable(EditorBrowsableState.Advanced)>
Protected Property IsSingleInstance() As Boolean
Get
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Imports Microsoft.VisualBasic.CompilerServices

Imports ExUtils = Microsoft.VisualBasic.CompilerServices.ExceptionUtils
Imports VbUtils = Microsoft.VisualBasic.CompilerServices.Utils
Imports NativeMethods = Microsoft.VisualBasic.CompilerServices.NativeMethods

Namespace Microsoft.VisualBasic

Expand Down
8 changes: 8 additions & 0 deletions src/Microsoft.VisualBasic.Forms/src/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Microsoft.VisualBasic.ApplicationServices.ApplyApplicationDefaultsEventArgs.ColorMode() -> System.Windows.Forms.SystemColorMode
Microsoft.VisualBasic.ApplicationServices.ApplyApplicationDefaultsEventArgs.ColorMode(AutoPropertyValue As System.Windows.Forms.SystemColorMode) -> Void
Microsoft.VisualBasic.ApplicationServices.ApplyApplicationDefaultsEventArgs.VisualStylesMode() -> System.Windows.Forms.VisualStylesMode
Microsoft.VisualBasic.ApplicationServices.ApplyApplicationDefaultsEventArgs.VisualStylesMode(AutoPropertyValue As System.Windows.Forms.VisualStylesMode) -> Void
Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.ColorMode() -> System.Windows.Forms.SystemColorMode
Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.ColorMode(value As System.Windows.Forms.SystemColorMode) -> Void
Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.VisualStylesMode() -> System.Windows.Forms.VisualStylesMode
Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.VisualStylesMode(value As System.Windows.Forms.VisualStylesMode) -> Void
20 changes: 19 additions & 1 deletion src/System.Drawing.Common/src/System/Drawing/SystemBrushes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ namespace System.Drawing;

public static class SystemBrushes
{
#if NET9_0_OR_GREATER
#pragma warning disable SYSLIB5002 // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed.
private static bool s_colorSetOnLastAccess = SystemColors.UseAlternativeColorSet;
#pragma warning restore SYSLIB5002 // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed.
#endif
private static readonly object s_systemBrushesKey = new();

public static Brush ActiveBorder => FromSystemColor(SystemColors.ActiveBorder);
Expand Down Expand Up @@ -57,7 +62,20 @@ public static Brush FromSystemColor(Color c)
throw new ArgumentException(SR.Format(SR.ColorNotSystemColor, c.ToString()));
}

if (!Gdip.ThreadData.TryGetValue(s_systemBrushesKey, out object? tempSystemBrushes) || tempSystemBrushes is not Brush[] systemBrushes)
#if NET9_0_OR_GREATER
#pragma warning disable SYSLIB5002 // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed.
if (s_colorSetOnLastAccess != SystemColors.UseAlternativeColorSet)
Copy link
Member

@JeremyKuhne JeremyKuhne Aug 5, 2024

Choose a reason for hiding this comment

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

The "right" way to do this is to poke the callbacks when you flip the color set. Probably best to look for $".NET-BroadcastEventWindow.{AppDomain.CurrentDomain.GetHashCode():x}.0" window and send the right message to it to get the SystemColorTracker to respond.

{
s_colorSetOnLastAccess = SystemColors.UseAlternativeColorSet;

// We need to clear the SystemBrushes cache, when the ColorMode had changed.
Gdip.ThreadData.Remove(s_systemBrushesKey);
}
#pragma warning restore SYSLIB5002 // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed.
#endif

if (!Gdip.ThreadData.TryGetValue(s_systemBrushesKey, out object? tempSystemBrushes)
|| tempSystemBrushes is not Brush[] systemBrushes)
{
systemBrushes = new Brush[(int)KnownColor.WindowText + (int)KnownColor.MenuHighlight - (int)KnownColor.YellowGreen];
Gdip.ThreadData[s_systemBrushesKey] = systemBrushes;
Expand Down
Loading
Loading