* 增加几个通用函数

This commit is contained in:
Sunny 2022-07-13 15:30:27 +08:00
parent a1b1b91049
commit 0aeff7da26
2 changed files with 65 additions and 12 deletions

View File

@ -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<string, Point> DragCtrlsPosition = new ConcurrentDictionary<string, Point>();
private static ConcurrentDictionary<string, bool> DragCtrlsMouseDown = new ConcurrentDictionary<string, bool>();
private static List<string> DragCtrlsAlreadyDrag = new List<string>();
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 _);
}
}
}
}

View File

@ -191,20 +191,20 @@ namespace Sunny.UI.Win32
internal class NatualOrderingComparer : IComparer<string>
{
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;