From e9d032d517d33e6ab36d3f19660ec923a2fccca3 Mon Sep 17 00:00:00 2001 From: Steve Cornett <21205494+stevecor@users.noreply.github.com> Date: Mon, 14 Sep 2026 07:57:51 -0700 Subject: [PATCH] Fix wxStaticBox for dark mode with double buffering Set custom painting mode for dark mode in MSWSetDarkOrLightMode() because custom painting mode is not set in Create() when double buffering. Fixes #27004. Closes #27007. --- include/wx/msw/statbox.h | 2 ++ src/msw/statbox.cpp | 13 +++++++++++++ 2 files changed, 15 insertions(+) diff --git a/include/wx/msw/statbox.h b/include/wx/msw/statbox.h index 8026ed76a5..12aefaff22 100644 --- a/include/wx/msw/statbox.h +++ b/include/wx/msw/statbox.h @@ -78,6 +78,8 @@ public: protected: virtual wxWindowList GetCompositeWindowParts() const override; + virtual void MSWSetDarkOrLightMode(SetMode setmode) override; + // return the region with all the windows inside this static box excluded WXHRGN MSWGetRegionWithoutChildren(); diff --git a/src/msw/statbox.cpp b/src/msw/statbox.cpp index 76bc9c602a..68a12f3ddf 100644 --- a/src/msw/statbox.cpp +++ b/src/msw/statbox.cpp @@ -95,6 +95,19 @@ bool wxStaticBox::Create(wxWindow *parent, return true; } +void wxStaticBox::MSWSetDarkOrLightMode(SetMode setmode) +{ + wxStaticBoxBase::MSWSetDarkOrLightMode(setmode); + + // Set custom painting because the native control does not support dark mode. + // + // Note that it's not useful to check if we're using dark mode now because + // we must either be starting to use it now or had been using it at some + // point for this function to be called and once custom painting is + // enabled, calling this function doesn't do anything anyhow. + UseCustomPaint(); +} + bool wxStaticBox::ShouldUseCustomPaint() const { // When not using double buffering, we paint the box ourselves by default