fix: suppress WM_ERASEBKGND to prevent drawing list flicker on quantity change

ListBox is a native Win32 control so ControlStyles.OptimizedDoubleBuffer
had no effect. The erase-then-redraw cycle on each Invalidate() caused
visible flashing. Suppressing WM_ERASEBKGND is safe because OnDrawItem
already fills the complete item bounds.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-04-06 22:42:00 -04:00
parent 959ab15491
commit 3c4d00baa4

View File

@@ -8,16 +8,14 @@ namespace OpenNest.Controls
public class DrawingListBox : ListBox public class DrawingListBox : ListBox
{ {
private const int WM_ERASEBKGND = 0x0014;
private readonly Size imageSize; private readonly Size imageSize;
private readonly Font nameFont; private readonly Font nameFont;
private Point lastClickLocation; private Point lastClickLocation;
public DrawingListBox() public DrawingListBox()
{ {
SetStyle(
ControlStyles.AllPaintingInWmPaint |
ControlStyles.OptimizedDoubleBuffer, true);
DrawMode = DrawMode.OwnerDrawFixed; DrawMode = DrawMode.OwnerDrawFixed;
ItemHeight = 85; ItemHeight = 85;
@@ -149,6 +147,16 @@ namespace OpenNest.Controls
base.OnMouseDown(e); base.OnMouseDown(e);
lastClickLocation = e.Location; lastClickLocation = e.Location;
} }
protected override void WndProc(ref Message m)
{
if (m.Msg == WM_ERASEBKGND)
{
m.Result = (IntPtr)1;
return;
}
base.WndProc(ref m);
}
} }
public static class PointExtensions public static class PointExtensions