diff --git a/src/System.Windows.Forms/System/Windows/Forms/Layout/Containers/SplitContainer.cs b/src/System.Windows.Forms/System/Windows/Forms/Layout/Containers/SplitContainer.cs index dbb1dded2f1..5fca905c8d4 100644 --- a/src/System.Windows.Forms/System/Windows/Forms/Layout/Containers/SplitContainer.cs +++ b/src/System.Windows.Forms/System/Windows/Forms/Layout/Containers/SplitContainer.cs @@ -1550,16 +1550,25 @@ private void RepaintSplitterRect() { if (IsHandleCreated) { - using Graphics g = CreateGraphicsInternal(); - if (BackgroundImage is not null) + try { - using TextureBrush textureBrush = new(BackgroundImage, WrapMode.Tile); - g.FillRectangle(textureBrush, ClientRectangle); + using Graphics g = CreateGraphicsInternal(); + if (BackgroundImage is not null) + { + using TextureBrush textureBrush = new(BackgroundImage, WrapMode.Tile); + g.FillRectangle(textureBrush, ClientRectangle); + } + else + { + using var solidBrush = BackColor.GetCachedSolidBrushScope(); + g.FillRectangle(solidBrush, _splitterRect); + } } - else + catch (ExternalException ex) { - using var solidBrush = BackColor.GetCachedSolidBrushScope(); - g.FillRectangle(solidBrush, _splitterRect); + // GDI+ can transiently fail while the display session is transitioning (for example, lock/unlock). + // Ignore repaint failures here and let normal painting recover once graphics resources are available. + Debug.Fail($"{nameof(RepaintSplitterRect)} failed with hr={ex.ErrorCode}, message={ex}"); } } }