From 8c74ca9553fbddc00797586ef2d74d432cbad5f4 Mon Sep 17 00:00:00 2001 From: Pilzinsel64 Date: Mon, 31 Jan 2022 14:04:12 +0000 Subject: [PATCH] recursive SuspendDrawing and ResumeDrawing --- Pilz.UI/Utilities/DrawingControl.vb | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/Pilz.UI/Utilities/DrawingControl.vb b/Pilz.UI/Utilities/DrawingControl.vb index 02b44a8..9dd45a4 100644 --- a/Pilz.UI/Utilities/DrawingControl.vb +++ b/Pilz.UI/Utilities/DrawingControl.vb @@ -1,4 +1,4 @@ -Imports System.Runtime.CompilerServices +Imports System.Runtime.CompilerServices Imports System.Windows.Forms Namespace Utils @@ -6,10 +6,19 @@ Namespace Utils Public Module DrawingControl Private Const WM_SETREDRAW = 11 + Private ReadOnly dicSuspendCount As New Dictionary(Of IntPtr, Integer) Public Sub SuspendDrawing(control As Control) - SendMessage(control.Handle, WM_SETREDRAW, False, 0) + If Not dicSuspendCount.ContainsKey(control.Handle) Then + dicSuspendCount.Add(control.Handle, 1) + Else + dicSuspendCount(control.Handle) += 1 + End If + + If dicSuspendCount(control.Handle) = 1 Then + SendMessage(control.Handle, WM_SETREDRAW, False, 0) + End If End Sub @@ -19,8 +28,19 @@ Namespace Utils Public Sub ResumeDrawing(control As Control, redraw As Boolean) - SendMessage(control.Handle, WM_SETREDRAW, True, 0) - If redraw Then control.Refresh() + Dim doRedraw As Boolean = True + + If dicSuspendCount.ContainsKey(control.Handle) Then + dicSuspendCount(control.Handle) -= 1 + If dicSuspendCount(control.Handle) >= 1 Then + doRedraw = False + End If + End If + + If doRedraw Then + SendMessage(control.Handle, WM_SETREDRAW, True, 0) + If redraw Then control.Refresh() + End If End Sub End Module