From 9828b9d6bc117a209a8515a073ffe9803a28ea22 Mon Sep 17 00:00:00 2001 From: AJ Isaacs Date: Tue, 10 Nov 2026 13:30:58 -0500 Subject: [PATCH] fix(drawing-list): paint the whole blank area when the side panel resizes Windows erases a resized window before WinForms updates its cached ClientSize, so the erase handler filled the blank area below the rows only out to the old width. Windows then treated the new strip as erased, and it kept whatever was on screen before. The handler now reads the client rect from Windows. Co-Authored-By: Claude Opus 5.5 --- OpenNest/Controls/DrawingListBox.cs | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/OpenNest/Controls/DrawingListBox.cs b/OpenNest/Controls/DrawingListBox.cs index a84aa221..60225e40 100644 --- a/OpenNest/Controls/DrawingListBox.cs +++ b/OpenNest/Controls/DrawingListBox.cs @@ -1,6 +1,7 @@ using System; using System.Drawing; using System.Linq; +using System.Runtime.InteropServices; using System.Windows.Forms; using Size = System.Drawing.Size; @@ -340,26 +341,32 @@ namespace OpenNest.Controls { if (m.Msg == WM_ERASEBKGND) { + // Windows erases a resized window before WinForms hears the new size, so the + // cached ClientSize still holds the old one; filling to it left the newly + // exposed strip unpainted (and validated, so nothing repainted it later). + GetClientRect(Handle, out var client); + var clientWidth = client.Right - client.Left; + var clientHeight = client.Bottom - client.Top; var itemBottom = 0; if (Items.Count > 0) { var lastVisible = System.Math.Min( - TopIndex + (ClientSize.Height / ItemHeight), + TopIndex + (clientHeight / ItemHeight), Items.Count - 1 ); itemBottom = GetItemRectangle(lastVisible).Bottom; } - if (itemBottom < ClientSize.Height) + if (itemBottom < clientHeight) { using var g = Graphics.FromHdc(m.WParam); g.FillRectangle( Brushes.White, 0, itemBottom, - ClientSize.Width, - ClientSize.Height - itemBottom + clientWidth, + clientHeight - itemBottom ); } @@ -372,6 +379,19 @@ namespace OpenNest.Controls if (m.Msg == WM_PAINT && IsShowingEmptyText) DrawEmptyText(); } + + [StructLayout(LayoutKind.Sequential)] + private struct RECT + { + public int Left; + public int Top; + public int Right; + public int Bottom; + } + + [DllImport("user32.dll")] + [return: MarshalAs(UnmanagedType.Bool)] + private static extern bool GetClientRect(IntPtr hWnd, out RECT rect); } public static class PointExtensions