* 增加XML文档文件
This commit is contained in:
parent
513c8cf171
commit
307ace2d85
@ -108,6 +108,10 @@ namespace Sunny.UI
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public uint ImportantColors { get; set; }
|
public uint ImportantColors { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 以图片初始化类
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="bitmap">图片</param>
|
||||||
public void Init(Bitmap bitmap)
|
public void Init(Bitmap bitmap)
|
||||||
{
|
{
|
||||||
Head = 0x4D42;
|
Head = 0x4D42;
|
||||||
@ -123,6 +127,11 @@ namespace Sunny.UI
|
|||||||
FileSize = BitmapDataOffset + BitmapDataSize;
|
FileSize = BitmapDataOffset + BitmapDataSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 以宽高初始化类
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="width">宽</param>
|
||||||
|
/// <param name="height">高</param>
|
||||||
public void Init(int width, int height)
|
public void Init(int width, int height)
|
||||||
{
|
{
|
||||||
Head = 0x4D42;
|
Head = 0x4D42;
|
||||||
@ -139,6 +148,9 @@ namespace Sunny.UI
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 24bit 真彩色位图文件
|
||||||
|
/// </summary>
|
||||||
public class BmpFile
|
public class BmpFile
|
||||||
{
|
{
|
||||||
BmpHead head;
|
BmpHead head;
|
||||||
@ -205,13 +217,24 @@ namespace Sunny.UI
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 二进制数据
|
||||||
|
/// </summary>
|
||||||
public byte[] Data => data;
|
public byte[] Data => data;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 保存文件
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="fileName">文件名</param>
|
||||||
public void SaveToFile(string fileName)
|
public void SaveToFile(string fileName)
|
||||||
{
|
{
|
||||||
File.WriteAllBytes(fileName, data);
|
File.WriteAllBytes(fileName, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 图片
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>图片</returns>
|
||||||
public Bitmap Bitmap()
|
public Bitmap Bitmap()
|
||||||
{
|
{
|
||||||
MemoryStream ms = new MemoryStream(data);
|
MemoryStream ms = new MemoryStream(data);
|
||||||
|
@ -36,6 +36,11 @@ namespace Sunny.UI
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public static class ControlEx
|
public static class ControlEx
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 定时器重置
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="timer">定时器</param>
|
||||||
|
/// <returns>定时器</returns>
|
||||||
public static Timer ReStart(this Timer timer)
|
public static Timer ReStart(this Timer timer)
|
||||||
{
|
{
|
||||||
timer.Stop();
|
timer.Stop();
|
||||||
@ -43,26 +48,51 @@ namespace Sunny.UI
|
|||||||
return timer;
|
return timer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 控件是否为空
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="ctrl">控件</param>
|
||||||
|
/// <returns>是否为空</returns>
|
||||||
public static bool IsNull(this Control ctrl)
|
public static bool IsNull(this Control ctrl)
|
||||||
{
|
{
|
||||||
return ctrl == null;
|
return ctrl == null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 控件是否有效
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="ctrl">控件</param>
|
||||||
|
/// <returns>是否有效</returns>
|
||||||
public static bool IsValid(this Control ctrl)
|
public static bool IsValid(this Control ctrl)
|
||||||
{
|
{
|
||||||
return ctrl != null;
|
return ctrl != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 控件位于屏幕的区域
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="ctrl">控件</param>
|
||||||
|
/// <returns>区域</returns>
|
||||||
public static Rectangle ScreenRectangle(this Control ctrl)
|
public static Rectangle ScreenRectangle(this Control ctrl)
|
||||||
{
|
{
|
||||||
return ctrl.RectangleToScreen(ctrl.ClientRectangle);
|
return ctrl.RectangleToScreen(ctrl.ClientRectangle);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 控件位于屏幕的位置
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="ctrl">控件</param>
|
||||||
|
/// <returns>位置</returns>
|
||||||
public static Point ScreenLocation(this Control ctrl)
|
public static Point ScreenLocation(this Control ctrl)
|
||||||
{
|
{
|
||||||
return ctrl.PointToScreen(new Point(0, 0));
|
return ctrl.PointToScreen(new Point(0, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 控件的根窗体
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="ctrl">控件</param>
|
||||||
|
/// <returns>根窗体</returns>
|
||||||
public static Form RootForm(this Control ctrl)
|
public static Form RootForm(this Control ctrl)
|
||||||
{
|
{
|
||||||
if (ctrl == null) return null;
|
if (ctrl == null) return null;
|
||||||
@ -74,11 +104,21 @@ namespace Sunny.UI
|
|||||||
return ctrl as Form;
|
return ctrl as Form;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 设置控件位于容器的中心
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="ctrl">控件</param>
|
||||||
|
/// <returns>控件</returns>
|
||||||
public static Control SetToTheCenterOfParent(this Control ctrl)
|
public static Control SetToTheCenterOfParent(this Control ctrl)
|
||||||
{
|
{
|
||||||
return ctrl.SetToTheHorizontalCenterOfParent().SetToTheVerticalCenterOfParent();
|
return ctrl.SetToTheHorizontalCenterOfParent().SetToTheVerticalCenterOfParent();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 设置控件位于容器的水平方向的中心
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="ctrl">控件</param>
|
||||||
|
/// <returns>控件</returns>
|
||||||
public static Control SetToTheHorizontalCenterOfParent(this Control ctrl)
|
public static Control SetToTheHorizontalCenterOfParent(this Control ctrl)
|
||||||
{
|
{
|
||||||
if (ctrl != null && ctrl.Parent != null)
|
if (ctrl != null && ctrl.Parent != null)
|
||||||
@ -87,6 +127,11 @@ namespace Sunny.UI
|
|||||||
return ctrl;
|
return ctrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 设置控件位于容器的垂直方向的中心
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="ctrl">控件</param>
|
||||||
|
/// <returns>控件</returns>
|
||||||
public static Control SetToTheVerticalCenterOfParent(this Control ctrl)
|
public static Control SetToTheVerticalCenterOfParent(this Control ctrl)
|
||||||
{
|
{
|
||||||
if (ctrl != null && ctrl.Parent != null)
|
if (ctrl != null && ctrl.Parent != null)
|
||||||
@ -95,26 +140,11 @@ namespace Sunny.UI
|
|||||||
return ctrl;
|
return ctrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Form GetParentForm(this Control ctrl)
|
|
||||||
{
|
|
||||||
while (!IsForm(ctrl.Parent))
|
|
||||||
{
|
|
||||||
ctrl = ctrl.Parent;
|
|
||||||
}
|
|
||||||
|
|
||||||
return ctrl.Parent as Form;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static bool IsForm(Control ctrl)
|
|
||||||
{
|
|
||||||
return ctrl is Form;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 边框宽度
|
/// 窗体边框宽度
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="form"></param>
|
/// <param name="form">窗体</param>
|
||||||
/// <returns></returns>
|
/// <returns>边框宽度</returns>
|
||||||
public static int BorderSize(this Form form)
|
public static int BorderSize(this Form form)
|
||||||
{
|
{
|
||||||
return (form.Width - form.ClientSize.Width) / 2;
|
return (form.Width - form.ClientSize.Width) / 2;
|
||||||
@ -123,8 +153,8 @@ namespace Sunny.UI
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 标题栏高度
|
/// 标题栏高度
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="form"></param>
|
/// <param name="form">窗体</param>
|
||||||
/// <returns></returns>
|
/// <returns>标题栏高度</returns>
|
||||||
public static int TitleHeight(this Form form)
|
public static int TitleHeight(this Form form)
|
||||||
{
|
{
|
||||||
return (form.Height - form.ClientSize.Height) - form.BorderSize();
|
return (form.Height - form.ClientSize.Height) - form.BorderSize();
|
||||||
|
@ -3,41 +3,124 @@ using System.Windows.Forms;
|
|||||||
|
|
||||||
namespace Sunny.UI
|
namespace Sunny.UI
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 日期控件选择类型
|
||||||
|
/// </summary>
|
||||||
public enum UIDateType
|
public enum UIDateType
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 年月日
|
||||||
|
/// </summary>
|
||||||
YearMonthDay,
|
YearMonthDay,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 年月
|
||||||
|
/// </summary>
|
||||||
YearMonth,
|
YearMonth,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 年
|
||||||
|
/// </summary>
|
||||||
Year
|
Year
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 接口
|
||||||
|
/// </summary>
|
||||||
public interface IToolTip
|
public interface IToolTip
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 需要额外设置工具提示的控件
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>控件</returns>
|
||||||
Control ExToolTipControl();
|
Control ExToolTipControl();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 线头部类型
|
||||||
|
/// </summary>
|
||||||
public enum UILineCap
|
public enum UILineCap
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 无
|
||||||
|
/// </summary>
|
||||||
None,
|
None,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 正方形
|
||||||
|
/// </summary>
|
||||||
Square,
|
Square,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 菱形
|
||||||
|
/// </summary>
|
||||||
Diamond,
|
Diamond,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 三角形
|
||||||
|
/// </summary>
|
||||||
Triangle,
|
Triangle,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 圆形
|
||||||
|
/// </summary>
|
||||||
Circle
|
Circle
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 线型
|
||||||
|
/// </summary>
|
||||||
public enum UILineDashStyle
|
public enum UILineDashStyle
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 实线
|
||||||
|
/// </summary>
|
||||||
Solid,
|
Solid,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 虚线
|
||||||
|
/// </summary>
|
||||||
Dash,
|
Dash,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 由重复的点图案构成的直线
|
||||||
|
/// </summary>
|
||||||
Dot,
|
Dot,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 由重复的点划线图案构成的直线
|
||||||
|
/// </summary>
|
||||||
DashDot,
|
DashDot,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 由重复的双点划线图案构成的直线
|
||||||
|
/// </summary>
|
||||||
DashDotDot,
|
DashDotDot,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 自定义
|
||||||
|
/// </summary>
|
||||||
Custom,
|
Custom,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 不设置线型
|
||||||
|
/// </summary>
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 树节点绘制
|
||||||
|
/// </summary>
|
||||||
public class UITreeNodePainter
|
public class UITreeNodePainter
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 背景色
|
||||||
|
/// </summary>
|
||||||
public Color BackColor;
|
public Color BackColor;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 前景色
|
||||||
|
/// </summary>
|
||||||
public Color ForeColor;
|
public Color ForeColor;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,14 +20,15 @@
|
|||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
|
|
||||||
using Microsoft.Win32;
|
using Microsoft.Win32;
|
||||||
using System;
|
|
||||||
|
|
||||||
namespace Sunny.UI
|
namespace Sunny.UI
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// .Net版本
|
||||||
|
/// </summary>
|
||||||
public static class UEnvironment
|
public static class UEnvironment
|
||||||
{
|
{
|
||||||
// Checking the version using >= enables forward compatibility.
|
private static string CheckFor45PlusVersion(int releaseKey)
|
||||||
public static string CheckFor45PlusVersion(int releaseKey)
|
|
||||||
{
|
{
|
||||||
if (releaseKey >= 528040)
|
if (releaseKey >= 528040)
|
||||||
return "4.8 or later";
|
return "4.8 or later";
|
||||||
@ -54,6 +55,10 @@ namespace Sunny.UI
|
|||||||
return "No 4.5 or later version detected";
|
return "No 4.5 or later version detected";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 检查.Net版本
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>.Net版本</returns>
|
||||||
public static string CheckVersion()
|
public static string CheckVersion()
|
||||||
{
|
{
|
||||||
const string subkey = @"SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full\";
|
const string subkey = @"SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full\";
|
||||||
@ -69,87 +74,5 @@ namespace Sunny.UI
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void CheckOtherVersion()
|
|
||||||
{
|
|
||||||
// Open the registry key for the .NET Framework entry.
|
|
||||||
using (RegistryKey ndpKey =
|
|
||||||
RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32)
|
|
||||||
.OpenSubKey(@"SOFTWARE\Microsoft\NET Framework Setup\NDP\"))
|
|
||||||
{
|
|
||||||
foreach (var versionKeyName in ndpKey.GetSubKeyNames())
|
|
||||||
{
|
|
||||||
// Skip .NET Framework 4.5 version information.
|
|
||||||
if (versionKeyName == "v4")
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (versionKeyName.StartsWith("v"))
|
|
||||||
{
|
|
||||||
RegistryKey versionKey = ndpKey.OpenSubKey(versionKeyName);
|
|
||||||
|
|
||||||
// Get the .NET Framework version value.
|
|
||||||
var name = (string)versionKey.GetValue("Version", "");
|
|
||||||
// Get the service pack (SP) number.
|
|
||||||
var sp = versionKey.GetValue("SP", "").ToString();
|
|
||||||
|
|
||||||
// Get the installation flag.
|
|
||||||
var install = versionKey.GetValue("Install", "").ToString();
|
|
||||||
if (string.IsNullOrEmpty(install))
|
|
||||||
{
|
|
||||||
// No install info; it must be in a child subkey.
|
|
||||||
Console.WriteLine($"{versionKeyName} {name}");
|
|
||||||
}
|
|
||||||
else if (install == "1")
|
|
||||||
{
|
|
||||||
// Install = 1 means the version is installed.
|
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(sp))
|
|
||||||
{
|
|
||||||
Console.WriteLine($"{versionKeyName} {name} SP{sp}");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Console.WriteLine($"{versionKeyName} {name}");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(name))
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
// else print out info from subkeys...
|
|
||||||
|
|
||||||
// Iterate through the subkeys of the version subkey.
|
|
||||||
foreach (var subKeyName in versionKey.GetSubKeyNames())
|
|
||||||
{
|
|
||||||
RegistryKey subKey = versionKey.OpenSubKey(subKeyName);
|
|
||||||
name = (string)subKey.GetValue("Version", "");
|
|
||||||
if (!string.IsNullOrEmpty(name))
|
|
||||||
sp = subKey.GetValue("SP", "").ToString();
|
|
||||||
|
|
||||||
install = subKey.GetValue("Install", "").ToString();
|
|
||||||
if (string.IsNullOrEmpty(install))
|
|
||||||
{
|
|
||||||
// No install info; it must be later.
|
|
||||||
Console.WriteLine($"{versionKeyName} {name}");
|
|
||||||
}
|
|
||||||
else if (install == "1")
|
|
||||||
{
|
|
||||||
if (!string.IsNullOrEmpty(sp))
|
|
||||||
{
|
|
||||||
Console.WriteLine($"{subKeyName} {name} SP{sp}");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Console.WriteLine($" {subKeyName} {name}");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -28,11 +28,7 @@
|
|||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace Sunny.UI
|
namespace Sunny.UI
|
||||||
{
|
{
|
||||||
@ -60,6 +56,9 @@ namespace Sunny.UI
|
|||||||
public static extern int FastLZ_Decompress(void* input, int length, void* output, int maxout);
|
public static extern int FastLZ_Decompress(void* input, int length, void* output, int maxout);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// FastLZ压缩解压类
|
||||||
|
/// </summary>
|
||||||
public static unsafe class FastLZ
|
public static unsafe class FastLZ
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -71,6 +70,13 @@ namespace Sunny.UI
|
|||||||
return IntPtr.Size == 8;
|
return IntPtr.Size == 8;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 压缩
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="input">输入</param>
|
||||||
|
/// <param name="begin">起始位置</param>
|
||||||
|
/// <param name="len">长度</param>
|
||||||
|
/// <returns>压缩结果</returns>
|
||||||
public static byte[] Compress(byte[] input, int begin, int len)
|
public static byte[] Compress(byte[] input, int begin, int len)
|
||||||
{
|
{
|
||||||
byte[] output = new byte[input.Length];
|
byte[] output = new byte[input.Length];
|
||||||
@ -84,6 +90,14 @@ namespace Sunny.UI
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 压缩
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="level">压缩级别</param>
|
||||||
|
/// <param name="input">输入</param>
|
||||||
|
/// <param name="begin">起始位置</param>
|
||||||
|
/// <param name="len">长度</param>
|
||||||
|
/// <returns>压缩结果</returns>
|
||||||
public static byte[] Compress(int level, byte[] input, int begin, int len)
|
public static byte[] Compress(int level, byte[] input, int begin, int len)
|
||||||
{
|
{
|
||||||
byte[] output = new byte[input.Length];
|
byte[] output = new byte[input.Length];
|
||||||
@ -97,6 +111,14 @@ namespace Sunny.UI
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 解压缩
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="input">输入</param>
|
||||||
|
/// <param name="begin">起始位置</param>
|
||||||
|
/// <param name="length">长度</param>
|
||||||
|
/// <param name="maxout">解压结果最大长度</param>
|
||||||
|
/// <returns>解压缩结果</returns>
|
||||||
public static byte[] Decompress(byte[] input, int begin, int length, int maxout)
|
public static byte[] Decompress(byte[] input, int begin, int length, int maxout)
|
||||||
{
|
{
|
||||||
byte[] output = new byte[maxout];
|
byte[] output = new byte[maxout];
|
||||||
|
@ -770,6 +770,11 @@ namespace Sunny.UI
|
|||||||
return crc.ToString("X").PadLeft(8, '0');
|
return crc.ToString("X").PadLeft(8, '0');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 文件名是否有效
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="name">文件名</param>
|
||||||
|
/// <returns>是否有效</returns>
|
||||||
public static bool IsValidFileName(string name)
|
public static bool IsValidFileName(string name)
|
||||||
{
|
{
|
||||||
if (name.IsNullOrEmpty())
|
if (name.IsNullOrEmpty())
|
||||||
|
@ -13,10 +13,23 @@ namespace Sunny.UI
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class FolderNameEditorEx : UITypeEditor
|
public class FolderNameEditorEx : UITypeEditor
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// GetEditStyle
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="context"></param>
|
||||||
|
/// <returns></returns>
|
||||||
public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context)
|
public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context)
|
||||||
{
|
{
|
||||||
return UITypeEditorEditStyle.Modal;
|
return UITypeEditorEditStyle.Modal;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// EditValue
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="context"></param>
|
||||||
|
/// <param name="provider"></param>
|
||||||
|
/// <param name="value"></param>
|
||||||
|
/// <returns></returns>
|
||||||
public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
|
public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
|
||||||
{
|
{
|
||||||
FolderBrowserDialogEx browser = new FolderBrowserDialogEx();
|
FolderBrowserDialogEx browser = new FolderBrowserDialogEx();
|
||||||
|
@ -27,6 +27,9 @@ using System.Drawing.Drawing2D;
|
|||||||
|
|
||||||
namespace Sunny.UI
|
namespace Sunny.UI
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// GDI扩展类
|
||||||
|
/// </summary>
|
||||||
public static class GDI
|
public static class GDI
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -57,6 +60,11 @@ namespace Sunny.UI
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 颜色是否是浅色
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="color">颜色</param>
|
||||||
|
/// <returns>是否是浅色</returns>
|
||||||
public static bool IsLightColor(this Color color)
|
public static bool IsLightColor(this Color color)
|
||||||
{
|
{
|
||||||
return (0.299 * color.R + 0.587 * color.G + 0.114 * color.B) / 255 > 0.5;
|
return (0.299 * color.R + 0.587 * color.G + 0.114 * color.B) / 255 > 0.5;
|
||||||
@ -65,29 +73,53 @@ namespace Sunny.UI
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 根据背景色判断前景色
|
/// 根据背景色判断前景色
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="backColor"></param>
|
/// <param name="backColor">背景色</param>
|
||||||
/// <returns></returns>
|
/// <returns>前景色</returns>
|
||||||
public static Color ForeColor(Color backColor)
|
public static Color ForeColor(Color backColor)
|
||||||
{
|
{
|
||||||
double gray = (0.299 * backColor.R + 0.587 * backColor.G + 0.114 * backColor.B) / 255;
|
return backColor.IsLightColor() ? Color.Black : Color.White;
|
||||||
return gray > 0.5 ? Color.Black : Color.White;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// SizeF转Size
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="size">SizeF</param>
|
||||||
|
/// <returns>Size</returns>
|
||||||
public static Size Size(this SizeF size)
|
public static Size Size(this SizeF size)
|
||||||
{
|
{
|
||||||
return new Size(size.Width.RoundEx(), size.Height.RoundEx());
|
return new Size(size.Width.RoundEx(), size.Height.RoundEx());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// PointF转Point
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="point">PointF</param>
|
||||||
|
/// <returns>Point</returns>
|
||||||
public static Point Point(this PointF point)
|
public static Point Point(this PointF point)
|
||||||
{
|
{
|
||||||
return new Point(point.X.RoundEx(), point.Y.RoundEx());
|
return new Point(point.X.RoundEx(), point.Y.RoundEx());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Size增加长宽
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="size">Size</param>
|
||||||
|
/// <param name="width">宽</param>
|
||||||
|
/// <param name="height">长</param>
|
||||||
|
/// <returns>结果</returns>
|
||||||
public static Size Add(this Size size, int width, int height)
|
public static Size Add(this Size size, int width, int height)
|
||||||
{
|
{
|
||||||
return new Size(size.Width + width, size.Height + height);
|
return new Size(size.Width + width, size.Height + height);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// SizeF增加长宽
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="size">SizeF</param>
|
||||||
|
/// <param name="width">宽</param>
|
||||||
|
/// <param name="height">长</param>
|
||||||
|
/// <returns>结果</returns>
|
||||||
public static SizeF Add(this SizeF size, float width, float height)
|
public static SizeF Add(this SizeF size, float width, float height)
|
||||||
{
|
{
|
||||||
return new SizeF(size.Width + width, size.Height + height);
|
return new SizeF(size.Width + width, size.Height + height);
|
||||||
@ -177,6 +209,13 @@ namespace Sunny.UI
|
|||||||
return Graphics().MeasureString(text, font);
|
return Graphics().MeasureString(text, font);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取起始颜色到终止颜色之间的渐变颜色
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="startColor">起始颜色</param>
|
||||||
|
/// <param name="endColor">终止颜色</param>
|
||||||
|
/// <param name="count">个数</param>
|
||||||
|
/// <returns>渐变颜色列表</returns>
|
||||||
public static Color[] GradientColors(this Color startColor, Color endColor, int count)
|
public static Color[] GradientColors(this Color startColor, Color endColor, int count)
|
||||||
{
|
{
|
||||||
count = Math.Max(count, 2);
|
count = Math.Max(count, 2);
|
||||||
@ -208,6 +247,12 @@ namespace Sunny.UI
|
|||||||
return colors;
|
return colors;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 开启高质量绘图
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="g">绘图图面</param>
|
||||||
|
/// <param name="smooth">是否平滑</param>
|
||||||
|
/// <returns>绘图图面</returns>
|
||||||
public static Graphics Smooth(this Graphics g, bool smooth = true)
|
public static Graphics Smooth(this Graphics g, bool smooth = true)
|
||||||
{
|
{
|
||||||
if (smooth)
|
if (smooth)
|
||||||
@ -222,17 +267,43 @@ namespace Sunny.UI
|
|||||||
return g;
|
return g;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 创建圆角路径
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="g">绘图图面</param>
|
||||||
|
/// <param name="rect">区域</param>
|
||||||
|
/// <param name="radius">圆角大小</param>
|
||||||
|
/// <param name="radiusSides">圆角的方位</param>
|
||||||
|
/// <returns>路径</returns>
|
||||||
public static GraphicsPath CreateRoundedRectanglePath(this Graphics g, Rectangle rect, int radius, UICornerRadiusSides radiusSides)
|
public static GraphicsPath CreateRoundedRectanglePath(this Graphics g, Rectangle rect, int radius, UICornerRadiusSides radiusSides)
|
||||||
{
|
{
|
||||||
return rect.CreateRoundedRectanglePath(radius, radiusSides);
|
return rect.CreateRoundedRectanglePath(radius, radiusSides);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 创建圆角路径
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="g">绘图图面</param>
|
||||||
|
/// <param name="rect">区域</param>
|
||||||
|
/// <param name="radius">圆角大小</param>
|
||||||
|
/// <param name="cornerLeftTop">左上角</param>
|
||||||
|
/// <param name="cornerRightTop">右上角</param>
|
||||||
|
/// <param name="cornerRightBottom">右下角</param>
|
||||||
|
/// <param name="cornerLeftBottom">左下角</param>
|
||||||
|
/// <returns>路径</returns>
|
||||||
public static GraphicsPath CreateRoundedRectanglePath(this Graphics g, Rectangle rect, int radius, bool cornerLeftTop = true, bool cornerRightTop = true, bool cornerRightBottom = true, bool cornerLeftBottom = true)
|
public static GraphicsPath CreateRoundedRectanglePath(this Graphics g, Rectangle rect, int radius, bool cornerLeftTop = true, bool cornerRightTop = true, bool cornerRightBottom = true, bool cornerLeftBottom = true)
|
||||||
{
|
{
|
||||||
return rect.CreateRoundedRectanglePath(radius, cornerLeftTop, cornerRightTop, cornerRightBottom, cornerLeftBottom);
|
return rect.CreateRoundedRectanglePath(radius, cornerLeftTop, cornerRightTop, cornerRightBottom, cornerLeftBottom);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 创建圆角路径
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="rect">区域</param>
|
||||||
|
/// <param name="radius">圆角大小</param>
|
||||||
|
/// <param name="radiusSides">圆角的方位</param>
|
||||||
|
/// <param name="lineSize">线宽</param>
|
||||||
|
/// <returns></returns>
|
||||||
public static GraphicsPath CreateRoundedRectanglePath(this Rectangle rect, int radius, UICornerRadiusSides radiusSides, int lineSize = 1)
|
public static GraphicsPath CreateRoundedRectanglePath(this Rectangle rect, int radius, UICornerRadiusSides radiusSides, int lineSize = 1)
|
||||||
{
|
{
|
||||||
GraphicsPath path;
|
GraphicsPath path;
|
||||||
@ -257,6 +328,11 @@ namespace Sunny.UI
|
|||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 绘图路径
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="rect">区域</param>
|
||||||
|
/// <returns>路径</returns>
|
||||||
public static GraphicsPath GraphicsPath(this Rectangle rect)
|
public static GraphicsPath GraphicsPath(this Rectangle rect)
|
||||||
{
|
{
|
||||||
Point[] points = new Point[] {
|
Point[] points = new Point[] {
|
||||||
@ -268,21 +344,59 @@ namespace Sunny.UI
|
|||||||
return points.Path();
|
return points.Path();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 创建扇形绘图路径
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="g">绘图图面</param>
|
||||||
|
/// <param name="center">圆心</param>
|
||||||
|
/// <param name="d1">内径</param>
|
||||||
|
/// <param name="d2">外径</param>
|
||||||
|
/// <param name="startAngle">起始角度</param>
|
||||||
|
/// <param name="sweepAngle">终止角度</param>
|
||||||
|
/// <returns>扇形绘图路径</returns>
|
||||||
public static GraphicsPath CreateFanPath(this Graphics g, Point center, float d1, float d2, float startAngle, float sweepAngle)
|
public static GraphicsPath CreateFanPath(this Graphics g, Point center, float d1, float d2, float startAngle, float sweepAngle)
|
||||||
{
|
{
|
||||||
return center.CreateFanPath(d1, d2, startAngle, sweepAngle);
|
return center.CreateFanPath(d1, d2, startAngle, sweepAngle);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 创建扇形绘图路径
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="g">绘图图面</param>
|
||||||
|
/// <param name="center">圆心</param>
|
||||||
|
/// <param name="d1">内径</param>
|
||||||
|
/// <param name="d2">外径</param>
|
||||||
|
/// <param name="startAngle">起始角度</param>
|
||||||
|
/// <param name="sweepAngle">终止角度</param>
|
||||||
|
/// <returns>扇形绘图路径</returns>
|
||||||
public static GraphicsPath CreateFanPath(this Graphics g, PointF center, float d1, float d2, float startAngle, float sweepAngle)
|
public static GraphicsPath CreateFanPath(this Graphics g, PointF center, float d1, float d2, float startAngle, float sweepAngle)
|
||||||
{
|
{
|
||||||
return center.CreateFanPath(d1, d2, startAngle, sweepAngle);
|
return center.CreateFanPath(d1, d2, startAngle, sweepAngle);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 创建扇形绘图路径
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="center">圆心</param>
|
||||||
|
/// <param name="d1">内径</param>
|
||||||
|
/// <param name="d2">外径</param>
|
||||||
|
/// <param name="startAngle">起始角度</param>
|
||||||
|
/// <param name="sweepAngle">终止角度</param>
|
||||||
|
/// <returns>扇形绘图路径</returns>
|
||||||
public static GraphicsPath CreateFanPath(this Point center, float d1, float d2, float startAngle, float sweepAngle)
|
public static GraphicsPath CreateFanPath(this Point center, float d1, float d2, float startAngle, float sweepAngle)
|
||||||
{
|
{
|
||||||
return new PointF(center.X, center.Y).CreateFanPath(d1, d2, startAngle, sweepAngle);
|
return new PointF(center.X, center.Y).CreateFanPath(d1, d2, startAngle, sweepAngle);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 创建扇形绘图路径
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="center">圆心</param>
|
||||||
|
/// <param name="d1">内径</param>
|
||||||
|
/// <param name="d2">外径</param>
|
||||||
|
/// <param name="startAngle">起始角度</param>
|
||||||
|
/// <param name="sweepAngle">终止角度</param>
|
||||||
|
/// <returns>扇形绘图路径</returns>
|
||||||
public static GraphicsPath CreateFanPath(this PointF center, float d1, float d2, float startAngle, float sweepAngle)
|
public static GraphicsPath CreateFanPath(this PointF center, float d1, float d2, float startAngle, float sweepAngle)
|
||||||
{
|
{
|
||||||
GraphicsPath path = new GraphicsPath();
|
GraphicsPath path = new GraphicsPath();
|
||||||
@ -292,6 +406,18 @@ namespace Sunny.UI
|
|||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 创建圆角路径
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="g">绘图图面</param>
|
||||||
|
/// <param name="rect">区域</param>
|
||||||
|
/// <param name="radius">圆角大小</param>
|
||||||
|
/// <param name="cornerLeftTop">左上角</param>
|
||||||
|
/// <param name="cornerRightTop">右上角</param>
|
||||||
|
/// <param name="cornerRightBottom">右下角</param>
|
||||||
|
/// <param name="cornerLeftBottom">左下角</param>
|
||||||
|
/// <param name="lineSize">线宽</param>
|
||||||
|
/// <returns>路径</returns>
|
||||||
public static GraphicsPath CreateRoundedRectanglePath(this Rectangle rect, int radius,
|
public static GraphicsPath CreateRoundedRectanglePath(this Rectangle rect, int radius,
|
||||||
bool cornerLeftTop = true, bool cornerRightTop = true, bool cornerRightBottom = true, bool cornerLeftBottom = true,
|
bool cornerLeftTop = true, bool cornerRightTop = true, bool cornerRightBottom = true, bool cornerLeftBottom = true,
|
||||||
int lineSize = 1)
|
int lineSize = 1)
|
||||||
@ -356,56 +482,116 @@ namespace Sunny.UI
|
|||||||
return g;
|
return g;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Color转HTML
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="color">Color</param>
|
||||||
|
/// <returns>HTML</returns>
|
||||||
public static string ToHTML(this Color color)
|
public static string ToHTML(this Color color)
|
||||||
{
|
{
|
||||||
return ColorTranslator.ToHtml(color);
|
return ColorTranslator.ToHtml(color);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// HTML转Color
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="htmlColor">HTML</param>
|
||||||
|
/// <param name="alpha">透明度</param>
|
||||||
|
/// <returns>Color</returns>
|
||||||
public static Color ToColor(this string htmlColor, int alpha = 255)
|
public static Color ToColor(this string htmlColor, int alpha = 255)
|
||||||
{
|
{
|
||||||
return Color.FromArgb(alpha > 255 ? 255 : alpha, ColorTranslator.FromHtml(htmlColor));
|
return Color.FromArgb(alpha > 255 ? 255 : alpha, ColorTranslator.FromHtml(htmlColor));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 颜色是否为空
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="color">颜色</param>
|
||||||
|
/// <returns>是否为空</returns>
|
||||||
public static bool IsNullOrEmpty(this Color color)
|
public static bool IsNullOrEmpty(this Color color)
|
||||||
{
|
{
|
||||||
return color == Color.Empty || color == Color.Transparent;
|
return color == Color.Empty || color == Color.Transparent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 画刷
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="color">颜色</param>
|
||||||
|
/// <returns>画刷</returns>
|
||||||
public static SolidBrush Brush(this Color color)
|
public static SolidBrush Brush(this Color color)
|
||||||
{
|
{
|
||||||
return new SolidBrush(color);
|
return new SolidBrush(color);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 画笔
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="color">颜色</param>
|
||||||
|
/// <param name="size">线宽</param>
|
||||||
|
/// <returns>画笔</returns>
|
||||||
public static Pen Pen(this Color color, float size = 1)
|
public static Pen Pen(this Color color, float size = 1)
|
||||||
{
|
{
|
||||||
return new Pen(color, size);
|
return new Pen(color, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// HTML颜色生成画刷
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="htmlColor">HTML颜色</param>
|
||||||
|
/// <param name="alpha">透明度</param>
|
||||||
|
/// <returns>画刷</returns>
|
||||||
public static SolidBrush Brush(this string htmlColor, int alpha = 255)
|
public static SolidBrush Brush(this string htmlColor, int alpha = 255)
|
||||||
{
|
{
|
||||||
return new SolidBrush(Color.FromArgb(alpha > 255 ? 255 : alpha, ColorTranslator.FromHtml(htmlColor)));
|
return new SolidBrush(Color.FromArgb(alpha > 255 ? 255 : alpha, ColorTranslator.FromHtml(htmlColor)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// HTML颜色生成画笔
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="htmlColor">HTML颜色</param>
|
||||||
|
/// <param name="alpha">透明度</param>
|
||||||
|
/// <param name="size">线宽</param>
|
||||||
|
/// <param name="startCap">起始线帽样式</param>
|
||||||
|
/// <param name="endCap">结束线帽样式</param>
|
||||||
|
/// <returns>画笔</returns>
|
||||||
public static Pen Pen(this string htmlColor, int alpha = 255, float size = 1, LineCap startCap = LineCap.Custom, LineCap endCap = LineCap.Custom)
|
public static Pen Pen(this string htmlColor, int alpha = 255, float size = 1, LineCap startCap = LineCap.Custom, LineCap endCap = LineCap.Custom)
|
||||||
{
|
{
|
||||||
return new Pen(Color.FromArgb(alpha > 255 ? 255 : alpha, ColorTranslator.FromHtml(htmlColor)), size) { StartCap = startCap, EndCap = endCap };
|
return new Pen(Color.FromArgb(alpha > 255 ? 255 : alpha, ColorTranslator.FromHtml(htmlColor)), size) { StartCap = startCap, EndCap = endCap };
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Font ToFont(this string fontName, float size, FontStyle fontStyle = FontStyle.Regular, GraphicsUnit unit = GraphicsUnit.Pixel)
|
/// <summary>
|
||||||
{
|
/// 渐变画刷
|
||||||
return new Font(fontName, size, fontStyle, unit);
|
/// </summary>
|
||||||
}
|
/// <param name="centerColor"></param>
|
||||||
|
/// <param name="surroundColor"></param>
|
||||||
|
/// <param name="point"></param>
|
||||||
|
/// <param name="gp"></param>
|
||||||
|
/// <param name="wrapMode"></param>
|
||||||
|
/// <returns></returns>
|
||||||
public static Brush GlowBrush(Color centerColor, Color[] surroundColor, PointF point, GraphicsPath gp, WrapMode wrapMode = WrapMode.Clamp)
|
public static Brush GlowBrush(Color centerColor, Color[] surroundColor, PointF point, GraphicsPath gp, WrapMode wrapMode = WrapMode.Clamp)
|
||||||
{
|
{
|
||||||
return new PathGradientBrush(gp) { CenterColor = centerColor, SurroundColors = surroundColor, FocusScales = point, WrapMode = wrapMode };
|
return new PathGradientBrush(gp) { CenterColor = centerColor, SurroundColors = surroundColor, FocusScales = point, WrapMode = wrapMode };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 渐变画刷
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="centerColor"></param>
|
||||||
|
/// <param name="surroundColor"></param>
|
||||||
|
/// <param name="point"></param>
|
||||||
|
/// <param name="wrapMode"></param>
|
||||||
|
/// <returns></returns>
|
||||||
public static Brush GlowBrush(Color centerColor, Color[] surroundColor, PointF[] point, WrapMode wrapMode = WrapMode.Clamp)
|
public static Brush GlowBrush(Color centerColor, Color[] surroundColor, PointF[] point, WrapMode wrapMode = WrapMode.Clamp)
|
||||||
{
|
{
|
||||||
return new PathGradientBrush(point) { CenterColor = centerColor, SurroundColors = surroundColor, WrapMode = wrapMode };
|
return new PathGradientBrush(point) { CenterColor = centerColor, SurroundColors = surroundColor, WrapMode = wrapMode };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 文本布局
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="horizontalAlignment">水平方向</param>
|
||||||
|
/// <param name="verticalAlignment">垂直方向</param>
|
||||||
|
/// <returns>文本布局</returns>
|
||||||
public static StringFormat SetAlignment(StringAlignment horizontalAlignment = StringAlignment.Center, StringAlignment verticalAlignment = StringAlignment.Center)
|
public static StringFormat SetAlignment(StringAlignment horizontalAlignment = StringAlignment.Center, StringAlignment verticalAlignment = StringAlignment.Center)
|
||||||
{
|
{
|
||||||
return new StringFormat { Alignment = horizontalAlignment, LineAlignment = verticalAlignment };
|
return new StringFormat { Alignment = horizontalAlignment, LineAlignment = verticalAlignment };
|
||||||
|
@ -41,8 +41,15 @@ using System.Windows.Forms;
|
|||||||
|
|
||||||
namespace Sunny.UI
|
namespace Sunny.UI
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// GIF图片帮助类
|
||||||
|
/// </summary>
|
||||||
public class Gif : IDisposable
|
public class Gif : IDisposable
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 构造函数
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="fileName">文件名</param>
|
||||||
public Gif(string fileName)
|
public Gif(string fileName)
|
||||||
{
|
{
|
||||||
timer = new Timer();
|
timer = new Timer();
|
||||||
@ -54,6 +61,10 @@ namespace Sunny.UI
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 构造函数
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="img">图片</param>
|
||||||
public Gif(Image img)
|
public Gif(Image img)
|
||||||
{
|
{
|
||||||
timer = new Timer();
|
timer = new Timer();
|
||||||
@ -79,11 +90,18 @@ namespace Sunny.UI
|
|||||||
ShowImage = null;
|
ShowImage = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 是否循环
|
||||||
|
/// </summary>
|
||||||
public bool Loop
|
public bool Loop
|
||||||
{
|
{
|
||||||
get; set;
|
get; set;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 跳帧
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="frameIndex">帧号</param>
|
||||||
public void JumpToFrame(int frameIndex)
|
public void JumpToFrame(int frameIndex)
|
||||||
{
|
{
|
||||||
if (ImageCount == 0) return;
|
if (ImageCount == 0) return;
|
||||||
@ -142,8 +160,16 @@ namespace Sunny.UI
|
|||||||
timer.Enabled = IsGif && active;
|
timer.Enabled = IsGif && active;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 图片切换事件
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender">对象</param>
|
||||||
|
/// <param name="image">图片</param>
|
||||||
public delegate void OnImageChanged(object sender, Image image);
|
public delegate void OnImageChanged(object sender, Image image);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 图片切换事件
|
||||||
|
/// </summary>
|
||||||
public event OnImageChanged ImageChanged;
|
public event OnImageChanged ImageChanged;
|
||||||
|
|
||||||
private readonly Timer timer;
|
private readonly Timer timer;
|
||||||
@ -151,8 +177,15 @@ namespace Sunny.UI
|
|||||||
private Image image;
|
private Image image;
|
||||||
|
|
||||||
private int ImageCount => image == null ? 0 : image.GifFrameCount();
|
private int ImageCount => image == null ? 0 : image.GifFrameCount();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 图片是否是GIF图片
|
||||||
|
/// </summary>
|
||||||
public bool IsGif => ImageCount > 0;
|
public bool IsGif => ImageCount > 0;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 图片
|
||||||
|
/// </summary>
|
||||||
public Image Image
|
public Image Image
|
||||||
{
|
{
|
||||||
get => image;
|
get => image;
|
||||||
@ -171,6 +204,9 @@ namespace Sunny.UI
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 刷新
|
||||||
|
/// </summary>
|
||||||
public void Invalidate()
|
public void Invalidate()
|
||||||
{
|
{
|
||||||
if (!Active)
|
if (!Active)
|
||||||
@ -181,6 +217,10 @@ namespace Sunny.UI
|
|||||||
|
|
||||||
private int FrameIndex;
|
private int FrameIndex;
|
||||||
private bool active;
|
private bool active;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 图片动画
|
||||||
|
/// </summary>
|
||||||
public bool Active
|
public bool Active
|
||||||
{
|
{
|
||||||
get => active;
|
get => active;
|
||||||
@ -193,13 +233,26 @@ namespace Sunny.UI
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// GIF图片帮助类
|
||||||
|
/// </summary>
|
||||||
public static class GifHelper
|
public static class GifHelper
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 获取图像框架的维度
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="img">图片</param>
|
||||||
|
/// <returns>图像框架的维度</returns>
|
||||||
public static FrameDimension GifFrameDimension(this Image img)
|
public static FrameDimension GifFrameDimension(this Image img)
|
||||||
{
|
{
|
||||||
return new FrameDimension(img.FrameDimensionsList[0]);
|
return new FrameDimension(img.FrameDimensionsList[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取图像的帧数
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="img">图像</param>
|
||||||
|
/// <returns>帧数</returns>
|
||||||
public static int GifFrameCount(this Image img)
|
public static int GifFrameCount(this Image img)
|
||||||
{
|
{
|
||||||
if (img == null) return 0;
|
if (img == null) return 0;
|
||||||
@ -207,6 +260,11 @@ namespace Sunny.UI
|
|||||||
return img.GetFrameCount(fd);
|
return img.GetFrameCount(fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取图像的帧间隔
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="img">图像</param>
|
||||||
|
/// <returns>帧间隔</returns>
|
||||||
public static int GifFrameInterval(this Image img)
|
public static int GifFrameInterval(this Image img)
|
||||||
{
|
{
|
||||||
FrameDimension dim = new FrameDimension(img.FrameDimensionsList[0]);
|
FrameDimension dim = new FrameDimension(img.FrameDimensionsList[0]);
|
||||||
|
@ -21,7 +21,7 @@
|
|||||||
<AssemblyOriginatorKeyFile>D:\MyDocuments\SunnyUI.pfx</AssemblyOriginatorKeyFile>
|
<AssemblyOriginatorKeyFile>D:\MyDocuments\SunnyUI.pfx</AssemblyOriginatorKeyFile>
|
||||||
<DelaySign>False</DelaySign>
|
<DelaySign>False</DelaySign>
|
||||||
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
|
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
|
||||||
<GenerateDocumentationFile>False</GenerateDocumentationFile>
|
<GenerateDocumentationFile>True</GenerateDocumentationFile>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
|
||||||
|
Loading…
x
Reference in New Issue
Block a user