change UI to UI.WinForms
This commit is contained in:
50
Pilz.UI.WinForms/Utilities/DrawingControl.cs
Normal file
50
Pilz.UI.WinForms/Utilities/DrawingControl.cs
Normal 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();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
48
Pilz.UI.WinForms/Utilities/DrawingControl.vb
Normal file
48
Pilz.UI.WinForms/Utilities/DrawingControl.vb
Normal 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
|
||||
9
Pilz.UI.WinForms/Utilities/User32Bridge.cs
Normal file
9
Pilz.UI.WinForms/Utilities/User32Bridge.cs
Normal 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);
|
||||
}
|
||||
5
Pilz.UI.WinForms/Utilities/User32Bridge.vb
Normal file
5
Pilz.UI.WinForms/Utilities/User32Bridge.vb
Normal 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
|
||||
Reference in New Issue
Block a user