From 0aeff7da265404adc57e118159d01ef9bfa685c7 Mon Sep 17 00:00:00 2001 From: Sunny Date: Wed, 13 Jul 2022 15:30:27 +0800 Subject: [PATCH] =?UTF-8?q?*=20=E5=A2=9E=E5=8A=A0=E5=87=A0=E4=B8=AA?= =?UTF-8?q?=E9=80=9A=E7=94=A8=E5=87=BD=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SunnyUI/Common/UControl.cs | 55 +++++++++++++++++++++++++++++++++++- SunnyUI/Win32/Win32.Added.cs | 22 +++++++-------- 2 files changed, 65 insertions(+), 12 deletions(-) diff --git a/SunnyUI/Common/UControl.cs b/SunnyUI/Common/UControl.cs index 41d4f819..ea05dbbc 100644 --- a/SunnyUI/Common/UControl.cs +++ b/SunnyUI/Common/UControl.cs @@ -20,6 +20,7 @@ ******************************************************************************/ using System; +using System.Collections.Concurrent; using System.Collections.Generic; using System.ComponentModel; using System.Drawing; @@ -543,12 +544,64 @@ namespace Sunny.UI public static void Disabled(this Control ctrl) { ctrl.Enabled = false; - ctrl.Hide(); } public static void Invisible(this Control ctrl) { ctrl.Visible = false; } + + private static ConcurrentDictionary DragCtrlsPosition = new ConcurrentDictionary(); + private static ConcurrentDictionary DragCtrlsMouseDown = new ConcurrentDictionary(); + private static List DragCtrlsAlreadyDrag = new List(); + + public static void AddDragEvent(this Control ctrl) + { + if (DragCtrlsPosition.NotContainsKey(ctrl.Name)) + { + DragCtrlsPosition.TryAdd(ctrl.Name, new Point()); + DragCtrlsMouseDown.TryAdd(ctrl.Name, false); + + if (DragCtrlsAlreadyDrag.Contains(ctrl.Name)) return; + DragCtrlsAlreadyDrag.Add(ctrl.Name); + + ctrl.MouseDown += (s, e) => + { + if (DragCtrlsMouseDown.ContainsKey(ctrl.Name)) + DragCtrlsMouseDown[ctrl.Name] = true; + + if (DragCtrlsPosition.ContainsKey(ctrl.Name)) + DragCtrlsPosition[ctrl.Name] = new Point(e.X, e.Y); + }; + + ctrl.MouseUp += (s, e) => + { + if (DragCtrlsMouseDown.ContainsKey(ctrl.Name)) + DragCtrlsMouseDown[ctrl.Name] = false; + }; + + ctrl.MouseMove += (s, e) => + { + if (DragCtrlsMouseDown.ContainsKey(ctrl.Name) && DragCtrlsPosition.ContainsKey(ctrl.Name)) + { + if (DragCtrlsMouseDown[ctrl.Name]) + { + int left = ctrl.Left + e.X - DragCtrlsPosition[ctrl.Name].X; + int top = ctrl.Top + e.Y - DragCtrlsPosition[ctrl.Name].Y; + ctrl.Location = new Point(left, top); + } + } + }; + } + } + + public static void RemoveDragEvent(this Control ctrl) + { + if (DragCtrlsPosition.ContainsKey(ctrl.Name)) + { + DragCtrlsPosition.TryRemove(ctrl.Name, out _); + DragCtrlsMouseDown.TryRemove(ctrl.Name, out _); + } + } } } \ No newline at end of file diff --git a/SunnyUI/Win32/Win32.Added.cs b/SunnyUI/Win32/Win32.Added.cs index 6bddac23..67063462 100644 --- a/SunnyUI/Win32/Win32.Added.cs +++ b/SunnyUI/Win32/Win32.Added.cs @@ -191,20 +191,20 @@ namespace Sunny.UI.Win32 internal class NatualOrderingComparer : IComparer { - static readonly Int32 NORM_IGNORECASE = 0x00000001; - static readonly Int32 NORM_IGNORENONSPACE = 0x00000002; - static readonly Int32 NORM_IGNORESYMBOLS = 0x00000004; - static readonly Int32 LINGUISTIC_IGNORECASE = 0x00000010; - static readonly Int32 LINGUISTIC_IGNOREDIACRITIC = 0x00000020; - static readonly Int32 NORM_IGNOREKANATYPE = 0x00010000; - static readonly Int32 NORM_IGNOREWIDTH = 0x00020000; - static readonly Int32 NORM_LINGUISTIC_CASING = 0x08000000; - static readonly Int32 SORT_STRINGSORT = 0x00001000; + //static readonly Int32 NORM_IGNORECASE = 0x00000001; + //static readonly Int32 NORM_IGNORENONSPACE = 0x00000002; + //static readonly Int32 NORM_IGNORESYMBOLS = 0x00000004; + //static readonly Int32 LINGUISTIC_IGNORECASE = 0x00000010; + //static readonly Int32 LINGUISTIC_IGNOREDIACRITIC = 0x00000020; + //static readonly Int32 NORM_IGNOREKANATYPE = 0x00010000; + //static readonly Int32 NORM_IGNOREWIDTH = 0x00020000; + //static readonly Int32 NORM_LINGUISTIC_CASING = 0x08000000; + //static readonly Int32 SORT_STRINGSORT = 0x00001000; static readonly Int32 SORT_DIGITSASNUMBERS = 0x00000008; - static readonly String LOCALE_NAME_USER_DEFAULT = null; + //static readonly String LOCALE_NAME_USER_DEFAULT = null; static readonly String LOCALE_NAME_INVARIANT = String.Empty; - static readonly String LOCALE_NAME_SYSTEM_DEFAULT = "!sys-default-locale"; + //static readonly String LOCALE_NAME_SYSTEM_DEFAULT = "!sys-default-locale"; readonly String locale;