@@ -7361,16 +7361,6 @@ protected virtual void OnHandleCreated(EventArgs e)
7361
7361
PInvoke . SetWindowText ( this , _text ) ;
7362
7362
}
7363
7363
7364
- #pragma warning disable WFO5001 // Type is for evaluation purposes only and is subject to change or removal in future updates.
7365
- if ( Application . IsDarkModeEnabled && GetStyle ( ControlStyles . ApplyThemingImplicitly ) )
7366
- {
7367
- _ = PInvoke . SetWindowTheme (
7368
- hwnd : HWND ,
7369
- pszSubAppName : $ "{ DarkModeIdentifier } _{ ExplorerThemeIdentifier } ",
7370
- pszSubIdList : null ) ;
7371
- }
7372
- #pragma warning restore WFO5001
7373
-
7374
7364
if ( this is not ScrollableControl
7375
7365
&& ! IsMirrored
7376
7366
&& GetExtendedState ( ExtendedStates . SetScrollPosition )
@@ -7380,6 +7370,18 @@ protected virtual void OnHandleCreated(EventArgs e)
7380
7370
SetExtendedState ( ExtendedStates . HaveInvoked , true ) ;
7381
7371
SetExtendedState ( ExtendedStates . SetScrollPosition , false ) ;
7382
7372
}
7373
+
7374
+ #pragma warning disable WFO5001 // Type is for evaluation purposes only and is subject to change or removal in future updates.
7375
+ if ( Application . IsDarkModeEnabled
7376
+ && GetStyle ( ControlStyles . ApplyThemingImplicitly )
7377
+ && ! RecreatingHandle )
7378
+ {
7379
+ _ = PInvoke . SetWindowTheme (
7380
+ hwnd : HWND ,
7381
+ pszSubAppName : $ "{ DarkModeIdentifier } _{ ExplorerThemeIdentifier } ",
7382
+ pszSubIdList : null ) ;
7383
+ }
7384
+ #pragma warning restore WFO5001
7383
7385
}
7384
7386
7385
7387
( ( EventHandler ? ) Events [ s_handleCreatedEvent ] ) ? . Invoke ( this , e ) ;
@@ -9323,6 +9325,21 @@ internal virtual void RecreateHandleCore()
9323
9325
}
9324
9326
}
9325
9327
9328
+ // Note that we need to take DarkMode theming into account at a different point in time
9329
+ // than when we create the handle for the first time. The reason is that recreating the handle
9330
+ // usually also recreates the handles of any child controls, and we want to
9331
+ // ensure that the theming is applied to all child controls as well.
9332
+ #pragma warning disable WFO5001 // Type is for evaluation purposes only and is subject to change or removal in future updates.
9333
+ if ( Application . IsDarkModeEnabled
9334
+ && GetStyle ( ControlStyles . ApplyThemingImplicitly ) )
9335
+ {
9336
+ _ = PInvoke . SetWindowTheme (
9337
+ hwnd : HWND ,
9338
+ pszSubAppName : $ "{ DarkModeIdentifier } _{ ExplorerThemeIdentifier } ",
9339
+ pszSubIdList : null ) ;
9340
+ }
9341
+ #pragma warning restore WFO5001
9342
+
9326
9343
// Restore control focus
9327
9344
if ( focused )
9328
9345
{
0 commit comments