change UI to UI.WinForms

This commit is contained in:
2025-06-16 11:50:17 +02:00
parent fa3a9da07e
commit 299867a910
116 changed files with 318 additions and 319 deletions

View File

@@ -0,0 +1,50 @@
using System.Collections.Generic;
using System.Windows.Forms;
namespace Pilz.UI.WinForms.Utilities;
public static class DrawingControl
{
private const int WM_SETREDRAW = 11;
private readonly static Dictionary<nint, int> dicSuspendCount = new Dictionary<nint, int>();
public static void SuspendDrawing(this Control control)
{
if (!dicSuspendCount.ContainsKey(control.Handle))
dicSuspendCount.Add(control.Handle, 1);
else
{
dicSuspendCount[control.Handle] += 1;
}
if (dicSuspendCount[control.Handle] == 1)
User32Bridge.SendMessage(control.Handle, WM_SETREDRAW, false, 0);
}
public static void ResumeDrawing(this Control control)
{
control.ResumeDrawing(true);
}
public static void ResumeDrawing(this Control control, bool redraw)
{
var doRedraw = true;
if (dicSuspendCount.ContainsKey(control.Handle))
{
dicSuspendCount[control.Handle] -= 1;
if (dicSuspendCount[control.Handle] >= 1)
doRedraw = false;
}
if (doRedraw)
{
User32Bridge.SendMessage(control.Handle, WM_SETREDRAW, true, 0);
if (redraw)
control.Refresh();
}
}
}

View File

@@ -0,0 +1,48 @@
Imports System.Runtime.CompilerServices
Imports System.Windows.Forms
Namespace Utils
Public Module DrawingControl
Private Const WM_SETREDRAW = 11
Private ReadOnly dicSuspendCount As New Dictionary(Of IntPtr, Integer)
<Extension>
Public Sub SuspendDrawing(control As Control)
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
<Extension>
Public Sub ResumeDrawing(control As Control)
ResumeDrawing(control, True)
End Sub
<Extension>
Public Sub ResumeDrawing(control As Control, redraw As Boolean)
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
End Namespace

View File

@@ -0,0 +1,9 @@
using System.Runtime.InteropServices;
namespace Pilz.UI.WinForms.Utilities;
public static class User32Bridge
{
[DllImport("user32.dll", CharSet = CharSet.Auto)]
internal static extern int SendMessage(nint hWnd, int Msg, bool wParam, int lParam);
}

View File

@@ -0,0 +1,5 @@
Public Module User32Bridge
Friend Declare Auto Function SendMessage Lib "user32.dll" (hWnd As IntPtr, Msg As Integer, wParam As Boolean, lParam As Integer) As Integer
End Module