2020-05-11 21:11:29 +08:00
|
|
|
|
/******************************************************************************
|
|
|
|
|
* SunnyUI 开源控件库、工具类库、扩展类库、多页面开发框架。
|
2023-01-07 18:12:33 +08:00
|
|
|
|
* CopyRight (C) 2012-2023 ShenYongHua(沈永华).
|
2021-02-20 15:45:47 +08:00
|
|
|
|
* QQ群:56829229 QQ:17612584 EMail:SunnyUI@QQ.Com
|
2020-05-11 21:11:29 +08:00
|
|
|
|
*
|
|
|
|
|
* Blog: https://www.cnblogs.com/yhuse
|
|
|
|
|
* Gitee: https://gitee.com/yhuse/SunnyUI
|
|
|
|
|
* GitHub: https://github.com/yhuse/SunnyUI
|
|
|
|
|
*
|
|
|
|
|
* SunnyUI.dll can be used for free under the GPL-3.0 license.
|
|
|
|
|
* If you use this code, please keep this note.
|
|
|
|
|
* 如果您使用此代码,请保留此说明。
|
|
|
|
|
******************************************************************************
|
|
|
|
|
* 文件名称: UIButton.cs
|
|
|
|
|
* 文件说明: 按钮
|
2022-01-05 21:57:47 +08:00
|
|
|
|
* 当前版本: V3.1
|
2020-05-11 21:11:29 +08:00
|
|
|
|
* 创建日期: 2020-01-01
|
|
|
|
|
*
|
|
|
|
|
* 2020-01-01: V2.2.0 增加文件说明
|
|
|
|
|
* 2020-04-25: V2.2.4 更新主题配置类
|
2020-07-30 21:21:47 +08:00
|
|
|
|
* 2020-07-26: V2.2.6 增加Selected及选中颜色配置
|
2020-09-17 21:20:47 +08:00
|
|
|
|
* 2020-08-22: V2.2.7 空格键按下press背景效果,添加双击事件,解决因快速点击导致过慢问题
|
|
|
|
|
* 2020-09-14: V2.2.7 Tips颜色可设置
|
2021-08-17 16:55:01 +08:00
|
|
|
|
* 2021-07-18: V3.0.5 增加ShowFocusColor,用来显示Focus状态
|
2021-12-11 00:10:46 +08:00
|
|
|
|
* 2021-12-11: V3.0.9 增加了渐变色
|
2022-02-26 10:28:54 +08:00
|
|
|
|
* 2022-02-26: V3.1.1 增加了AutoSize属性
|
2022-03-20 17:16:40 +08:00
|
|
|
|
* 2022-03-19: V3.1.1 重构主题配色
|
2022-03-31 16:44:23 +08:00
|
|
|
|
* 2022-03-31: V3.1.2 是否显示浅色背景
|
2022-08-25 15:20:50 +08:00
|
|
|
|
* 2022-08-25: V3.2.3 增加同一个容器的相同GroupIndex的按钮控件的Selected单选
|
2020-05-11 21:11:29 +08:00
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
|
|
using System;
|
2022-08-25 15:20:50 +08:00
|
|
|
|
using System.Collections.Generic;
|
2020-05-11 21:11:29 +08:00
|
|
|
|
using System.ComponentModel;
|
|
|
|
|
using System.Drawing;
|
2020-06-23 23:21:53 +08:00
|
|
|
|
using System.Drawing.Drawing2D;
|
2020-05-11 21:11:29 +08:00
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
|
|
|
|
|
// ReSharper disable All
|
|
|
|
|
|
|
|
|
|
namespace Sunny.UI
|
|
|
|
|
{
|
2022-06-24 15:04:08 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 按钮
|
|
|
|
|
/// </summary>
|
2020-05-11 21:11:29 +08:00
|
|
|
|
[DefaultEvent("Click")]
|
|
|
|
|
[DefaultProperty("Text")]
|
|
|
|
|
[ToolboxItem(true)]
|
2020-06-23 23:21:53 +08:00
|
|
|
|
public class UIButton : UIControl, IButtonControl
|
2020-05-11 21:11:29 +08:00
|
|
|
|
{
|
2022-06-24 15:04:08 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 构造函数
|
|
|
|
|
/// </summary>
|
2020-05-11 21:11:29 +08:00
|
|
|
|
public UIButton()
|
|
|
|
|
{
|
2021-04-16 15:45:58 +08:00
|
|
|
|
SetStyleFlags();
|
2020-05-11 21:11:29 +08:00
|
|
|
|
TabStop = true;
|
|
|
|
|
Width = 100;
|
|
|
|
|
Height = 35;
|
|
|
|
|
Cursor = Cursors.Hand;
|
|
|
|
|
|
2022-03-20 17:16:40 +08:00
|
|
|
|
foreHoverColor = UIStyles.Blue.ButtonForeHoverColor;
|
|
|
|
|
forePressColor = UIStyles.Blue.ButtonForePressColor;
|
|
|
|
|
foreSelectedColor = UIStyles.Blue.ButtonForeSelectedColor;
|
2020-05-11 21:11:29 +08:00
|
|
|
|
|
2022-03-20 17:16:40 +08:00
|
|
|
|
rectHoverColor = UIStyles.Blue.ButtonRectHoverColor;
|
|
|
|
|
rectPressColor = UIStyles.Blue.ButtonRectPressColor;
|
|
|
|
|
rectSelectedColor = UIStyles.Blue.ButtonRectSelectedColor;
|
2020-05-11 21:11:29 +08:00
|
|
|
|
|
2022-03-20 17:16:40 +08:00
|
|
|
|
fillHoverColor = UIStyles.Blue.ButtonFillHoverColor;
|
|
|
|
|
fillPressColor = UIStyles.Blue.ButtonFillPressColor;
|
|
|
|
|
fillSelectedColor = UIStyles.Blue.ButtonFillSelectedColor;
|
2020-08-24 12:06:46 +08:00
|
|
|
|
SetStyle(ControlStyles.StandardDoubleClick, UseDoubleClick);
|
2020-05-11 21:11:29 +08:00
|
|
|
|
}
|
|
|
|
|
|
2022-06-24 15:04:08 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 是否显示浅色背景
|
|
|
|
|
/// </summary>
|
2022-03-31 16:44:23 +08:00
|
|
|
|
[DefaultValue(false)]
|
|
|
|
|
[Description("是否显示浅色背景"), Category("SunnyUI")]
|
|
|
|
|
public bool LightStyle
|
|
|
|
|
{
|
|
|
|
|
get => lightStyle;
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (lightStyle != value)
|
|
|
|
|
{
|
|
|
|
|
lightStyle = value;
|
|
|
|
|
Invalidate();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-26 10:28:54 +08:00
|
|
|
|
private bool autoSize;
|
|
|
|
|
|
2022-06-24 15:04:08 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 自动大小
|
|
|
|
|
/// </summary>
|
2022-02-26 10:28:54 +08:00
|
|
|
|
[Browsable(true), DefaultValue(false)]
|
|
|
|
|
[Description("自动大小"), Category("SunnyUI")]
|
|
|
|
|
public override bool AutoSize
|
|
|
|
|
{
|
|
|
|
|
get => autoSize;
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
autoSize = value;
|
|
|
|
|
Invalidate();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-01 22:52:50 +08:00
|
|
|
|
private bool isClick;
|
|
|
|
|
|
2022-06-24 15:04:08 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 调用点击事件
|
|
|
|
|
/// </summary>
|
2020-06-01 22:52:50 +08:00
|
|
|
|
public void PerformClick()
|
|
|
|
|
{
|
|
|
|
|
if (isClick) return;
|
|
|
|
|
if (CanSelect && Enabled)
|
|
|
|
|
{
|
|
|
|
|
isClick = true;
|
|
|
|
|
OnClick(EventArgs.Empty);
|
|
|
|
|
isClick = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-24 15:04:08 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 重载点击事件
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="e">参数</param>
|
2020-06-23 23:21:53 +08:00
|
|
|
|
protected override void OnClick(EventArgs e)
|
|
|
|
|
{
|
2021-12-11 00:10:46 +08:00
|
|
|
|
Form form = FindFormInternal();
|
|
|
|
|
if (form != null) form.DialogResult = DialogResult;
|
|
|
|
|
|
2020-06-23 23:21:53 +08:00
|
|
|
|
Focus();
|
|
|
|
|
base.OnClick(e);
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-11 00:10:46 +08:00
|
|
|
|
internal Form FindFormInternal()
|
|
|
|
|
{
|
|
|
|
|
Control cur = this;
|
|
|
|
|
while (cur != null && !(cur is Form))
|
|
|
|
|
{
|
|
|
|
|
cur = cur.Parent;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (Form)cur;
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-11 21:11:29 +08:00
|
|
|
|
private bool showTips = false;
|
|
|
|
|
|
2022-06-24 15:04:08 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 是否显示角标
|
|
|
|
|
/// </summary>
|
2020-08-07 20:20:15 +08:00
|
|
|
|
[Description("是否显示角标"), Category("SunnyUI")]
|
2020-05-11 21:11:29 +08:00
|
|
|
|
[DefaultValue(false)]
|
|
|
|
|
public bool ShowTips
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return showTips;
|
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (showTips != value)
|
|
|
|
|
{
|
|
|
|
|
showTips = value;
|
|
|
|
|
Invalidate();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private string tipsText = "";
|
|
|
|
|
|
2022-06-24 15:04:08 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 角标文字
|
|
|
|
|
/// </summary>
|
2020-08-07 20:20:15 +08:00
|
|
|
|
[Description("角标文字"), Category("SunnyUI")]
|
2020-05-11 21:11:29 +08:00
|
|
|
|
[DefaultValue("")]
|
|
|
|
|
public string TipsText
|
|
|
|
|
{
|
|
|
|
|
get { return tipsText; }
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (tipsText != value)
|
|
|
|
|
{
|
|
|
|
|
tipsText = value;
|
|
|
|
|
if (ShowTips)
|
|
|
|
|
{
|
|
|
|
|
Invalidate();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-02 12:19:45 +08:00
|
|
|
|
private Font tipsFont = UIFontColor.SubFont();
|
2020-05-11 21:11:29 +08:00
|
|
|
|
|
2022-06-24 15:04:08 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 角标文字字体
|
|
|
|
|
/// </summary>
|
2020-08-07 20:20:15 +08:00
|
|
|
|
[Description("角标文字字体"), Category("SunnyUI")]
|
2022-01-02 12:19:45 +08:00
|
|
|
|
[DefaultValue(typeof(Font), "微软雅黑, 9pt")]
|
2020-05-11 21:11:29 +08:00
|
|
|
|
public Font TipsFont
|
|
|
|
|
{
|
|
|
|
|
get { return tipsFont; }
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (!tipsFont.Equals(value))
|
|
|
|
|
{
|
|
|
|
|
tipsFont = value;
|
|
|
|
|
Invalidate();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-23 23:27:55 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 绘制填充颜色
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="g">绘图图面</param>
|
|
|
|
|
/// <param name="path">绘图路径</param>
|
2020-07-26 19:18:00 +08:00
|
|
|
|
protected override void OnPaintFill(Graphics g, GraphicsPath path)
|
|
|
|
|
{
|
2021-12-11 00:10:46 +08:00
|
|
|
|
if (FillColorGradient)
|
2020-07-26 19:18:00 +08:00
|
|
|
|
{
|
2022-06-27 17:36:58 +08:00
|
|
|
|
if (IsHover || IsPress || Selected || Disabled)
|
2021-12-11 00:10:46 +08:00
|
|
|
|
{
|
|
|
|
|
base.OnPaintFill(g, path);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
LinearGradientBrush br = new LinearGradientBrush(new Point(0, 0), new Point(0, Height), FillColor, FillColor2);
|
|
|
|
|
br.GammaCorrection = true;
|
|
|
|
|
g.FillPath(br, path);
|
|
|
|
|
br.Dispose();
|
|
|
|
|
}
|
2020-07-26 19:18:00 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2021-12-11 00:10:46 +08:00
|
|
|
|
base.OnPaintFill(g, path);
|
2020-07-26 19:18:00 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-14 21:31:09 +08:00
|
|
|
|
private Color tipsColor = Color.Red;
|
|
|
|
|
|
2022-06-24 15:04:08 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 角标背景颜色
|
|
|
|
|
/// </summary>
|
2021-08-27 10:38:48 +08:00
|
|
|
|
[Description("角标背景颜色"), Category("SunnyUI")]
|
2020-09-14 21:31:09 +08:00
|
|
|
|
[DefaultValue(typeof(Color), "Red")]
|
|
|
|
|
public Color TipsColor
|
|
|
|
|
{
|
|
|
|
|
get => tipsColor;
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
tipsColor = value;
|
|
|
|
|
Invalidate();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-27 10:38:48 +08:00
|
|
|
|
private Color tipsForeColor = Color.White;
|
|
|
|
|
|
2022-06-24 15:04:08 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 角标文字颜色
|
|
|
|
|
/// </summary>
|
2021-08-27 10:38:48 +08:00
|
|
|
|
[DefaultValue(typeof(Color), "White"), Category("SunnyUI"), Description("角标文字颜色")]
|
|
|
|
|
public Color TipsForeColor
|
|
|
|
|
{
|
|
|
|
|
get => tipsForeColor;
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
tipsForeColor = value;
|
|
|
|
|
Invalidate();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-06 15:48:59 +08:00
|
|
|
|
Font tmpFont;
|
|
|
|
|
|
|
|
|
|
private Font TempFont
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
if (tmpFont == null || !tmpFont.Size.EqualsFloat(TipsFont.DPIScaleFontSize()))
|
|
|
|
|
{
|
|
|
|
|
tmpFont?.Dispose();
|
|
|
|
|
tmpFont = TipsFont.DPIScaleFont();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return tmpFont;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-24 15:04:08 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 析构函数
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="disposing">释放参数</param>
|
2021-12-06 15:48:59 +08:00
|
|
|
|
protected override void Dispose(bool disposing)
|
|
|
|
|
{
|
|
|
|
|
base.Dispose(disposing);
|
|
|
|
|
tmpFont?.Dispose();
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-24 15:04:08 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 重载绘图
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="e">绘图参数</param>
|
2020-05-11 21:11:29 +08:00
|
|
|
|
protected override void OnPaint(PaintEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
base.OnPaint(e);
|
|
|
|
|
|
2022-02-26 10:28:54 +08:00
|
|
|
|
if (autoSize && Dock == DockStyle.None)
|
|
|
|
|
{
|
|
|
|
|
SizeF sf = e.Graphics.MeasureString(Text, Font);
|
|
|
|
|
if (Width != (int)(sf.Width) + 6) Width = (int)(sf.Width) + 6;
|
|
|
|
|
if (Height != (int)(sf.Height) + 6) Height = (int)(sf.Height) + 6;
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-11 21:11:29 +08:00
|
|
|
|
if (Enabled && ShowTips && !string.IsNullOrEmpty(TipsText))
|
|
|
|
|
{
|
|
|
|
|
e.Graphics.SetHighQuality();
|
2021-12-06 15:48:59 +08:00
|
|
|
|
SizeF sf = e.Graphics.MeasureString(TipsText, TempFont);
|
2020-05-11 21:11:29 +08:00
|
|
|
|
float sfMax = Math.Max(sf.Width, sf.Height);
|
|
|
|
|
float x = Width - 1 - 2 - sfMax;
|
|
|
|
|
float y = 1 + 1;
|
2020-09-14 21:31:09 +08:00
|
|
|
|
e.Graphics.FillEllipse(TipsColor, x, y, sfMax, sfMax);
|
2021-12-06 15:48:59 +08:00
|
|
|
|
e.Graphics.DrawString(TipsText, TempFont, TipsForeColor, x + sfMax / 2.0f - sf.Width / 2.0f, y + sfMax / 2.0f - sf.Height / 2.0f);
|
2020-05-11 21:11:29 +08:00
|
|
|
|
}
|
2020-06-23 23:21:53 +08:00
|
|
|
|
|
|
|
|
|
if (Focused && ShowFocusLine)
|
|
|
|
|
{
|
|
|
|
|
Rectangle rect = new Rectangle(2, 2, Width - 5, Height - 5);
|
|
|
|
|
var path = rect.CreateRoundedRectanglePath(Radius);
|
|
|
|
|
using (Pen pn = new Pen(ForeColor))
|
|
|
|
|
{
|
|
|
|
|
pn.DashStyle = DashStyle.Dot;
|
|
|
|
|
e.Graphics.DrawPath(pn, path);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
path.Dispose();
|
|
|
|
|
}
|
2020-05-11 21:11:29 +08:00
|
|
|
|
}
|
2020-08-07 20:20:15 +08:00
|
|
|
|
|
2020-05-11 21:11:29 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 是否选中
|
|
|
|
|
/// </summary>
|
|
|
|
|
[DefaultValue(false)]
|
2020-08-08 21:55:50 +08:00
|
|
|
|
[Description("是否选中"), Category("SunnyUI")]
|
2020-05-11 21:11:29 +08:00
|
|
|
|
public bool Selected
|
|
|
|
|
{
|
|
|
|
|
get => selected;
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (selected != value)
|
|
|
|
|
{
|
|
|
|
|
selected = value;
|
|
|
|
|
Invalidate();
|
2022-08-25 15:20:50 +08:00
|
|
|
|
|
|
|
|
|
if (value && Parent != null)
|
|
|
|
|
{
|
|
|
|
|
if (this is UISymbolButton)
|
|
|
|
|
{
|
|
|
|
|
List<UISymbolButton> buttons = Parent.GetControls<UISymbolButton>();
|
|
|
|
|
|
|
|
|
|
foreach (var box in buttons)
|
|
|
|
|
{
|
|
|
|
|
if (box == this) continue;
|
|
|
|
|
if (box.GroupIndex != GroupIndex) continue;
|
|
|
|
|
if (box.Selected) box.Selected = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (this is UIButton)
|
|
|
|
|
{
|
|
|
|
|
List<UIButton> buttons = Parent.GetControls<UIButton>();
|
|
|
|
|
|
|
|
|
|
foreach (var box in buttons)
|
|
|
|
|
{
|
|
|
|
|
if (box is UISymbolButton) continue;
|
|
|
|
|
if (box == this) continue;
|
|
|
|
|
if (box.GroupIndex != GroupIndex) continue;
|
|
|
|
|
if (box.Selected) box.Selected = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-05-11 21:11:29 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-23 23:27:55 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 设置主题样式
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="uiColor">主题样式</param>
|
2020-05-11 21:11:29 +08:00
|
|
|
|
public override void SetStyleColor(UIBaseStyle uiColor)
|
|
|
|
|
{
|
|
|
|
|
base.SetStyleColor(uiColor);
|
2022-03-20 17:16:40 +08:00
|
|
|
|
|
2020-05-11 21:11:29 +08:00
|
|
|
|
fillHoverColor = uiColor.ButtonFillHoverColor;
|
2022-03-20 17:16:40 +08:00
|
|
|
|
rectHoverColor = uiColor.ButtonRectHoverColor;
|
2020-05-11 21:11:29 +08:00
|
|
|
|
foreHoverColor = uiColor.ButtonForeHoverColor;
|
|
|
|
|
|
|
|
|
|
fillPressColor = uiColor.ButtonFillPressColor;
|
2022-03-20 17:16:40 +08:00
|
|
|
|
rectPressColor = uiColor.ButtonRectPressColor;
|
2020-05-11 21:11:29 +08:00
|
|
|
|
forePressColor = uiColor.ButtonForePressColor;
|
|
|
|
|
|
2020-07-26 19:18:00 +08:00
|
|
|
|
fillSelectedColor = uiColor.ButtonFillSelectedColor;
|
|
|
|
|
foreSelectedColor = uiColor.ButtonForeSelectedColor;
|
2022-03-20 17:16:40 +08:00
|
|
|
|
rectSelectedColor = uiColor.ButtonRectSelectedColor;
|
2020-05-11 21:11:29 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 填充颜色,当值为背景色或透明色或空值则不填充
|
|
|
|
|
/// </summary>
|
2020-08-07 20:20:15 +08:00
|
|
|
|
[Description("填充颜色"), Category("SunnyUI")]
|
2020-05-11 21:11:29 +08:00
|
|
|
|
[DefaultValue(typeof(Color), "80, 160, 255")]
|
|
|
|
|
public Color FillColor
|
|
|
|
|
{
|
|
|
|
|
get => fillColor;
|
|
|
|
|
set => SetFillColor(value);
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-11 00:10:46 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 填充颜色,当值为背景色或透明色或空值则不填充
|
|
|
|
|
/// </summary>
|
|
|
|
|
[Description("填充颜色"), Category("SunnyUI")]
|
|
|
|
|
[DefaultValue(typeof(Color), "80, 160, 255")]
|
|
|
|
|
public Color FillColor2
|
|
|
|
|
{
|
|
|
|
|
get => fillColor2;
|
|
|
|
|
set => SetFillColor2(value);
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-24 15:04:08 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 填充颜色渐变
|
|
|
|
|
/// </summary>
|
2021-12-11 00:10:46 +08:00
|
|
|
|
[Description("填充颜色渐变"), Category("SunnyUI")]
|
|
|
|
|
[DefaultValue(false)]
|
|
|
|
|
public bool FillColorGradient
|
|
|
|
|
{
|
|
|
|
|
get => fillColorGradient;
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (fillColorGradient != value)
|
|
|
|
|
{
|
|
|
|
|
fillColorGradient = value;
|
|
|
|
|
Invalidate();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-11 21:11:29 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 边框颜色
|
|
|
|
|
/// </summary>
|
2020-08-07 20:20:15 +08:00
|
|
|
|
[Description("边框颜色"), Category("SunnyUI")]
|
2020-05-11 21:11:29 +08:00
|
|
|
|
[DefaultValue(typeof(Color), "80, 160, 255")]
|
|
|
|
|
public Color RectColor
|
|
|
|
|
{
|
|
|
|
|
get => rectColor;
|
|
|
|
|
set => SetRectColor(value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 字体颜色
|
|
|
|
|
/// </summary>
|
2020-08-07 20:20:15 +08:00
|
|
|
|
[Description("字体颜色"), Category("SunnyUI")]
|
2020-05-11 21:11:29 +08:00
|
|
|
|
[DefaultValue(typeof(Color), "White")]
|
|
|
|
|
public override Color ForeColor
|
|
|
|
|
{
|
|
|
|
|
get => foreColor;
|
|
|
|
|
set => SetForeColor(value);
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-24 15:04:08 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 不可用时填充颜色
|
|
|
|
|
/// </summary>
|
2020-08-07 20:20:15 +08:00
|
|
|
|
[DefaultValue(typeof(Color), "244, 244, 244"), Category("SunnyUI")]
|
2020-08-08 21:55:50 +08:00
|
|
|
|
[Description("不可用时填充颜色")]
|
2020-05-11 21:11:29 +08:00
|
|
|
|
public Color FillDisableColor
|
|
|
|
|
{
|
|
|
|
|
get => fillDisableColor;
|
|
|
|
|
set => SetFillDisableColor(value);
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-24 15:04:08 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 不可用时边框颜色
|
|
|
|
|
/// </summary>
|
2020-08-07 20:20:15 +08:00
|
|
|
|
[DefaultValue(typeof(Color), "173, 178, 181"), Category("SunnyUI")]
|
2020-08-08 21:55:50 +08:00
|
|
|
|
[Description("不可用时边框颜色")]
|
2020-05-11 21:11:29 +08:00
|
|
|
|
public Color RectDisableColor
|
|
|
|
|
{
|
|
|
|
|
get => rectDisableColor;
|
|
|
|
|
set => SetRectDisableColor(value);
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-24 15:04:08 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 不可用时字体颜色
|
|
|
|
|
/// </summary>
|
2020-08-07 20:20:15 +08:00
|
|
|
|
[DefaultValue(typeof(Color), "109, 109, 103"), Category("SunnyUI")]
|
2020-08-08 21:55:50 +08:00
|
|
|
|
[Description("不可用时字体颜色")]
|
2020-05-11 21:11:29 +08:00
|
|
|
|
public Color ForeDisableColor
|
|
|
|
|
{
|
|
|
|
|
get => foreDisableColor;
|
|
|
|
|
set => SetForeDisableColor(value);
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-24 15:04:08 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 鼠标移上时填充颜色
|
|
|
|
|
/// </summary>
|
2022-03-20 17:16:40 +08:00
|
|
|
|
[DefaultValue(typeof(Color), "115, 179, 255"), Category("SunnyUI")]
|
2020-08-08 21:55:50 +08:00
|
|
|
|
[Description("鼠标移上时填充颜色")]
|
2020-05-11 21:11:29 +08:00
|
|
|
|
public Color FillHoverColor
|
|
|
|
|
{
|
|
|
|
|
get => fillHoverColor;
|
2022-03-20 17:16:40 +08:00
|
|
|
|
set => SetFillHoverColor(value);
|
2020-05-11 21:11:29 +08:00
|
|
|
|
}
|
|
|
|
|
|
2022-06-24 15:04:08 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 鼠标按下时填充颜色
|
|
|
|
|
/// </summary>
|
2022-03-20 17:16:40 +08:00
|
|
|
|
[DefaultValue(typeof(Color), "64, 128, 204"), Category("SunnyUI")]
|
2020-08-08 21:55:50 +08:00
|
|
|
|
[Description("鼠标按下时填充颜色")]
|
2020-05-11 21:11:29 +08:00
|
|
|
|
public Color FillPressColor
|
|
|
|
|
{
|
|
|
|
|
get => fillPressColor;
|
|
|
|
|
set => SetFillPressColor(value);
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-24 15:04:08 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 鼠标移上时字体颜色
|
|
|
|
|
/// </summary>
|
2020-08-07 20:20:15 +08:00
|
|
|
|
[DefaultValue(typeof(Color), "White"), Category("SunnyUI")]
|
2020-08-08 21:55:50 +08:00
|
|
|
|
[Description("鼠标移上时字体颜色")]
|
2020-05-11 21:11:29 +08:00
|
|
|
|
public Color ForeHoverColor
|
|
|
|
|
{
|
|
|
|
|
get => foreHoverColor;
|
2022-03-20 17:16:40 +08:00
|
|
|
|
set => SetForeHoverColor(value);
|
2020-05-11 21:11:29 +08:00
|
|
|
|
}
|
|
|
|
|
|
2022-06-24 15:04:08 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 鼠标按下时字体颜色
|
|
|
|
|
/// </summary>
|
2020-08-07 20:20:15 +08:00
|
|
|
|
[DefaultValue(typeof(Color), "White"), Category("SunnyUI")]
|
2020-08-08 21:55:50 +08:00
|
|
|
|
[Description("鼠标按下时字体颜色")]
|
2020-05-11 21:11:29 +08:00
|
|
|
|
public Color ForePressColor
|
|
|
|
|
{
|
|
|
|
|
get => forePressColor;
|
|
|
|
|
set => SetForePressColor(value);
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-24 15:04:08 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 鼠标移上时边框颜色
|
|
|
|
|
/// </summary>
|
2022-03-20 17:16:40 +08:00
|
|
|
|
[DefaultValue(typeof(Color), "115, 179, 255"), Category("SunnyUI")]
|
2020-08-08 21:55:50 +08:00
|
|
|
|
[Description("鼠标移上时边框颜色")]
|
2020-05-11 21:11:29 +08:00
|
|
|
|
public Color RectHoverColor
|
|
|
|
|
{
|
|
|
|
|
get => rectHoverColor;
|
2022-03-20 17:16:40 +08:00
|
|
|
|
set => SetRectHoverColor(value);
|
2020-05-11 21:11:29 +08:00
|
|
|
|
}
|
|
|
|
|
|
2022-06-24 15:04:08 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 鼠标按下时边框颜色
|
|
|
|
|
/// </summary>
|
2022-03-20 17:16:40 +08:00
|
|
|
|
[DefaultValue(typeof(Color), "64, 128, 204"), Category("SunnyUI")]
|
2020-08-08 21:55:50 +08:00
|
|
|
|
[Description("鼠标按下时边框颜色")]
|
2020-05-11 21:11:29 +08:00
|
|
|
|
public Color RectPressColor
|
|
|
|
|
{
|
|
|
|
|
get => rectPressColor;
|
|
|
|
|
set => SetRectPressColor(value);
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-24 15:04:08 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 选中时填充颜色
|
|
|
|
|
/// </summary>
|
2022-03-20 17:16:40 +08:00
|
|
|
|
[DefaultValue(typeof(Color), "64, 128, 204"), Category("SunnyUI")]
|
2020-08-08 21:55:50 +08:00
|
|
|
|
[Description("选中时填充颜色")]
|
2020-07-26 19:18:00 +08:00
|
|
|
|
public Color FillSelectedColor
|
|
|
|
|
{
|
|
|
|
|
get => fillSelectedColor;
|
|
|
|
|
set => SetFillSelectedColor(value);
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-24 15:04:08 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 选中时字体颜色
|
|
|
|
|
/// </summary>
|
2020-08-07 20:20:15 +08:00
|
|
|
|
[DefaultValue(typeof(Color), "White"), Category("SunnyUI")]
|
2020-08-08 21:55:50 +08:00
|
|
|
|
[Description("选中时字体颜色")]
|
2020-07-26 19:18:00 +08:00
|
|
|
|
public Color ForeSelectedColor
|
|
|
|
|
{
|
|
|
|
|
get => foreSelectedColor;
|
|
|
|
|
set => SetForeSelectedColor(value);
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-24 15:04:08 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 选中时边框颜色
|
|
|
|
|
/// </summary>
|
2022-03-20 17:16:40 +08:00
|
|
|
|
[DefaultValue(typeof(Color), "64, 128, 204"), Category("SunnyUI")]
|
2020-08-08 21:55:50 +08:00
|
|
|
|
[Description("选中时边框颜色")]
|
2020-07-26 19:18:00 +08:00
|
|
|
|
public Color RectSelectedColor
|
2020-05-11 21:11:29 +08:00
|
|
|
|
{
|
2020-07-26 19:18:00 +08:00
|
|
|
|
get => rectSelectedColor;
|
|
|
|
|
set => SetRectSelectedColor(value);
|
2020-05-11 21:11:29 +08:00
|
|
|
|
}
|
|
|
|
|
|
2022-06-24 15:04:08 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 重载鼠标按下事件
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="e">鼠标参数</param>
|
2020-05-11 21:11:29 +08:00
|
|
|
|
protected override void OnMouseDown(MouseEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
base.OnMouseDown(e);
|
|
|
|
|
IsPress = true;
|
|
|
|
|
Invalidate();
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-24 15:04:08 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 重载鼠标抬起事件
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="e">鼠标参数</param>
|
2020-05-11 21:11:29 +08:00
|
|
|
|
protected override void OnMouseUp(MouseEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
base.OnMouseUp(e);
|
|
|
|
|
IsPress = false;
|
|
|
|
|
Invalidate();
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-24 15:04:08 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 重载鼠标离开事件
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="e">鼠标参数</param>
|
2020-05-11 21:11:29 +08:00
|
|
|
|
protected override void OnMouseLeave(EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
base.OnMouseLeave(e);
|
|
|
|
|
IsPress = false;
|
|
|
|
|
IsHover = false;
|
|
|
|
|
Invalidate();
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-24 15:04:08 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 重载鼠标进入事件
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="e">鼠标参数</param>
|
2020-05-11 21:11:29 +08:00
|
|
|
|
protected override void OnMouseEnter(EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
base.OnMouseEnter(e);
|
|
|
|
|
IsHover = true;
|
|
|
|
|
Invalidate();
|
|
|
|
|
}
|
2020-06-23 23:21:53 +08:00
|
|
|
|
|
2022-06-24 15:04:08 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 通知控件它是默认按钮
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="value"></param>
|
2020-06-23 23:21:53 +08:00
|
|
|
|
public void NotifyDefault(bool value)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-24 15:04:08 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 指定标识符以指示对话框的返回值
|
|
|
|
|
/// </summary>
|
2020-06-23 23:21:53 +08:00
|
|
|
|
[DefaultValue(DialogResult.None)]
|
2020-08-08 21:55:50 +08:00
|
|
|
|
[Description("指定标识符以指示对话框的返回值"), Category("SunnyUI")]
|
2020-06-23 23:21:53 +08:00
|
|
|
|
public DialogResult DialogResult { get; set; } = DialogResult.None;
|
|
|
|
|
|
2022-06-24 15:04:08 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 键盘按下事件
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="e">按键参数</param>
|
2020-06-23 23:21:53 +08:00
|
|
|
|
protected override void OnKeyDown(KeyEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (Focused && e.KeyCode == Keys.Space)
|
|
|
|
|
{
|
2020-08-22 18:31:20 +08:00
|
|
|
|
IsPress = true;
|
|
|
|
|
Invalidate();
|
2020-06-23 23:21:53 +08:00
|
|
|
|
PerformClick();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
base.OnKeyDown(e);
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-24 15:04:08 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 键盘抬起事件
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="e">按键参数</param>
|
2020-08-22 18:31:20 +08:00
|
|
|
|
protected override void OnKeyUp(KeyEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
IsPress = false;
|
|
|
|
|
Invalidate();
|
|
|
|
|
|
|
|
|
|
base.OnKeyUp(e);
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-24 15:04:08 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 显示激活时边框线
|
|
|
|
|
/// </summary>
|
2020-06-23 23:21:53 +08:00
|
|
|
|
[DefaultValue(false)]
|
2020-08-08 21:55:50 +08:00
|
|
|
|
[Description("显示激活时边框线"), Category("SunnyUI")]
|
2020-06-23 23:21:53 +08:00
|
|
|
|
public bool ShowFocusLine { get; set; }
|
2022-08-25 15:20:50 +08:00
|
|
|
|
|
|
|
|
|
[DefaultValue(0)]
|
|
|
|
|
[Description("分组编号"), Category("SunnyUI")]
|
|
|
|
|
public int GroupIndex { get; set; }
|
2020-05-11 21:11:29 +08:00
|
|
|
|
}
|
|
|
|
|
}
|