* UIButton,UIPanel:增加了渐变色

This commit is contained in:
Sunny 2021-12-11 00:10:46 +08:00
parent 6fc54cf7e8
commit b606394638
9 changed files with 296 additions and 88 deletions

Binary file not shown.

View File

@ -222,7 +222,7 @@ namespace Sunny.UI
return rect.CreateRoundedRectanglePath(radius, cornerLeftTop, cornerRightTop, cornerRightBottom, cornerLeftBottom); return rect.CreateRoundedRectanglePath(radius, cornerLeftTop, cornerRightTop, cornerRightBottom, cornerLeftBottom);
} }
public static GraphicsPath CreateRoundedRectanglePath(this Rectangle rect, int radius, UICornerRadiusSides radiusSides) public static GraphicsPath CreateRoundedRectanglePath(this Rectangle rect, int radius, UICornerRadiusSides radiusSides, int lineSize = 1)
{ {
GraphicsPath path; GraphicsPath path;
@ -240,7 +240,7 @@ namespace Sunny.UI
bool RadiusRightTop = radiusSides.GetValue(UICornerRadiusSides.RightTop); bool RadiusRightTop = radiusSides.GetValue(UICornerRadiusSides.RightTop);
//IsRadius为True时显示右下圆角 //IsRadius为True时显示右下圆角
bool RadiusRightBottom = radiusSides.GetValue(UICornerRadiusSides.RightBottom); bool RadiusRightBottom = radiusSides.GetValue(UICornerRadiusSides.RightBottom);
path = rect.CreateRoundedRectanglePath(radius, RadiusLeftTop, RadiusRightTop, RadiusRightBottom, RadiusLeftBottom); path = rect.CreateRoundedRectanglePath(radius, RadiusLeftTop, RadiusRightTop, RadiusRightBottom, RadiusLeftBottom, lineSize);
} }
return path; return path;
@ -281,7 +281,9 @@ namespace Sunny.UI
return path; return path;
} }
public static GraphicsPath CreateRoundedRectanglePath(this Rectangle rect, int radius, bool cornerLeftTop = true, bool cornerRightTop = true, bool cornerRightBottom = true, bool cornerLeftBottom = true) public static GraphicsPath CreateRoundedRectanglePath(this Rectangle rect, int radius,
bool cornerLeftTop = true, bool cornerRightTop = true, bool cornerRightBottom = true, bool cornerLeftBottom = true,
int lineSize = 1)
{ {
GraphicsPath path = new GraphicsPath(); GraphicsPath path = new GraphicsPath();
@ -291,6 +293,7 @@ namespace Sunny.UI
} }
else else
{ {
radius *= lineSize;
if (cornerLeftTop) if (cornerLeftTop)
path.AddArc(rect.X, rect.Y, radius, radius, 180, 90); path.AddArc(rect.X, rect.Y, radius, radius, 180, 90);
else else
@ -311,6 +314,7 @@ namespace Sunny.UI
else else
path.AddLine(new Point(rect.X + 1, rect.Y + rect.Height), new Point(rect.X, rect.Y + rect.Height)); path.AddLine(new Point(rect.X + 1, rect.Y + rect.Height), new Point(rect.X, rect.Y + rect.Height));
path.CloseFigure(); path.CloseFigure();
} }

View File

@ -22,6 +22,7 @@
* 2020-08-22: V2.2.7 press背景效果 * 2020-08-22: V2.2.7 press背景效果
* 2020-09-14: V2.2.7 Tips颜色可设置 * 2020-09-14: V2.2.7 Tips颜色可设置
* 2021-07-18: V3.0.5 ShowFocusColorFocus状态 * 2021-07-18: V3.0.5 ShowFocusColorFocus状态
* 2021-12-11: V3.0.9
******************************************************************************/ ******************************************************************************/
using System; using System;
@ -76,10 +77,24 @@ namespace Sunny.UI
protected override void OnClick(EventArgs e) protected override void OnClick(EventArgs e)
{ {
Form form = FindFormInternal();
if (form != null) form.DialogResult = DialogResult;
Focus(); Focus();
base.OnClick(e); base.OnClick(e);
} }
internal Form FindFormInternal()
{
Control cur = this;
while (cur != null && !(cur is Form))
{
cur = cur.Parent;
}
return (Form)cur;
}
private bool showTips = false; private bool showTips = false;
[Description("是否显示角标"), Category("SunnyUI")] [Description("是否显示角标"), Category("SunnyUI")]
@ -139,13 +154,23 @@ namespace Sunny.UI
protected override void OnPaintFill(Graphics g, GraphicsPath path) protected override void OnPaintFill(Graphics g, GraphicsPath path)
{ {
if (!selected) if (FillColorGradient)
{ {
base.OnPaintFill(g, path); if (IsHover || IsPress || Selected)
{
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();
}
} }
else else
{ {
g.FillPath(FillSelectedColor, path); base.OnPaintFill(g, path);
} }
} }
@ -274,6 +299,32 @@ namespace Sunny.UI
set => SetFillColor(value); set => SetFillColor(value);
} }
/// <summary>
/// 填充颜色,当值为背景色或透明色或空值则不填充
/// </summary>
[Description("填充颜色"), Category("SunnyUI")]
[DefaultValue(typeof(Color), "80, 160, 255")]
public Color FillColor2
{
get => fillColor2;
set => SetFillColor2(value);
}
[Description("填充颜色渐变"), Category("SunnyUI")]
[DefaultValue(false)]
public bool FillColorGradient
{
get => fillColorGradient;
set
{
if (fillColorGradient != value)
{
fillColorGradient = value;
Invalidate();
}
}
}
/// <summary> /// <summary>
/// 边框颜色 /// 边框颜色
/// </summary> /// </summary>

View File

@ -261,6 +261,7 @@ namespace Sunny.UI
public virtual void SetStyleColor(UIBaseStyle uiColor) public virtual void SetStyleColor(UIBaseStyle uiColor)
{ {
fillColor = uiColor.ButtonFillColor; fillColor = uiColor.ButtonFillColor;
fillColor2 = uiColor.ButtonFillColor2;
rectColor = uiColor.RectColor; rectColor = uiColor.RectColor;
foreColor = uiColor.ButtonForeColor; foreColor = uiColor.ButtonForeColor;
@ -352,7 +353,7 @@ namespace Sunny.UI
if (IsDisposed) return; if (IsDisposed) return;
Rectangle rect = new Rectangle(0, 0, Width - 1, Height - 1); Rectangle rect = new Rectangle(0, 0, Width - 1, Height - 1);
GraphicsPath path = rect.CreateRoundedRectanglePath(radius, RadiusSides); GraphicsPath path = rect.CreateRoundedRectanglePath(radius, RadiusSides, RectSize);
//填充背景色 //填充背景色
if (ShowFill && fillColor.IsValid()) if (ShowFill && fillColor.IsValid())
@ -452,6 +453,29 @@ namespace Sunny.UI
g.FillPath(color, path); g.FillPath(color, path);
} }
private int rectSize = 1;
/// <summary>
/// 边框颜色
/// </summary>
[Description("边框宽度"), Category("SunnyUI")]
[DefaultValue(1)]
public int RectSize
{
get => rectSize;
set
{
int v = value;
if (v > 2) v = 2;
if (v < 1) v = 1;
if (rectSize != v)
{
rectSize = v;
Invalidate();
}
}
}
private void PaintRectDisableSides(Graphics g) private void PaintRectDisableSides(Graphics g)
{ {
//IsRadius为False时显示左侧边线 //IsRadius为False时显示左侧边线
@ -472,85 +496,86 @@ namespace Sunny.UI
//IsRadius为True时显示右下圆角 //IsRadius为True时显示右下圆角
bool RadiusRightBottom = RadiusSides.GetValue(UICornerRadiusSides.RightBottom); bool RadiusRightBottom = RadiusSides.GetValue(UICornerRadiusSides.RightBottom);
var ShowRadius = RadiusSides > 0; var ShowRadius = RadiusSides > 0;//肯定少有一个角显示圆角
using (Pen pen = new Pen(GetFillColor()))
using (Pen penR = new Pen(GetRectColor())) if (!ShowRadius || (!RadiusLeftBottom && !RadiusLeftTop))
{
g.DrawLine(GetRectColor(), 0, 0, 0, Height - 1);
}
if (!ShowRadius || (!RadiusRightTop && !RadiusLeftTop))
{
g.DrawLine(GetRectColor(), 0, 0, Width - 1, 0);
}
if (!ShowRadius || (!RadiusRightTop && !RadiusRightBottom))
{
g.DrawLine(GetRectColor(), Width - 1, 0, Width - 1, Height - 1);
}
if (!ShowRadius || (!RadiusLeftBottom && !RadiusRightBottom))
{
g.DrawLine(GetRectColor(), 0, Height - 1, Width - 1, Height - 1);
}
if (!ShowRectLeft)
{ {
if (!ShowRadius || (!RadiusLeftBottom && !RadiusLeftTop)) if (!ShowRadius || (!RadiusLeftBottom && !RadiusLeftTop))
{ {
g.DrawLine(penR, 0, 0, 0, Height - 1); g.DrawLine(GetFillColor(), 0, RectSize, 0, Height - 1 - RectSize);
if (RectSize == 2) g.DrawLine(GetFillColor(), 1, RectSize, 1, Height - 1 - RectSize);
} }
}
if (!ShowRectTop)
{
if (!ShowRadius || (!RadiusRightTop && !RadiusLeftTop)) if (!ShowRadius || (!RadiusRightTop && !RadiusLeftTop))
{ {
g.DrawLine(penR, 0, 0, Width - 1, 0); g.DrawLine(GetFillColor(), RectSize, 0, Width - 1 - RectSize, 0);
if (RectSize == 2) g.DrawLine(GetFillColor(), RectSize, 1, Width - 1 - RectSize, 1);
} }
}
if (!ShowRectRight)
{
if (!ShowRadius || (!RadiusRightTop && !RadiusRightBottom)) if (!ShowRadius || (!RadiusRightTop && !RadiusRightBottom))
{ {
g.DrawLine(penR, Width - 1, 0, Width - 1, Height - 1); g.DrawLine(GetFillColor(), Width - 1, RectSize, Width - 1, Height - 1 - RectSize);
if (RectSize == 2) g.DrawLine(GetFillColor(), Width - 2, RectSize, Width - 2, Height - 1 - RectSize);
} }
}
if (!ShowRectBottom)
{
if (!ShowRadius || (!RadiusLeftBottom && !RadiusRightBottom)) if (!ShowRadius || (!RadiusLeftBottom && !RadiusRightBottom))
{ {
g.DrawLine(penR, 0, Height - 1, Width - 1, Height - 1); g.DrawLine(GetFillColor(), RectSize, Height - 1, Width - 1 - RectSize, Height - 1);
if (RectSize == 2) g.DrawLine(GetFillColor(), RectSize, Height - 2, Width - 1 - RectSize, Height - 2);
} }
}
if (!ShowRectLeft) if (!ShowRectLeft && !ShowRectTop)
{ {
if (!ShowRadius || (!RadiusLeftBottom && !RadiusLeftTop)) if (!ShowRadius || (!RadiusLeftBottom && !RadiusLeftTop))
{ g.FillRectangle(GetFillColor(), 0, 0, RectSize, RectSize);
g.DrawLine(pen, 0, 1, 0, Height - 2); }
}
}
if (!ShowRectTop) if (!ShowRectRight && !ShowRectTop)
{ {
if (!ShowRadius || (!RadiusRightTop && !RadiusLeftTop)) if (!ShowRadius || (!RadiusLeftBottom && !RadiusLeftTop))
{ g.FillRectangle(GetFillColor(), Width - 1 - RectSize, 0, RectSize, RectSize);
g.DrawLine(pen, 1, 0, Width - 2, 0); }
}
}
if (!ShowRectRight) if (!ShowRectLeft && !ShowRectBottom)
{ {
if (!ShowRadius || (!RadiusRightTop && !RadiusRightBottom)) if (!ShowRadius || (!RadiusLeftBottom && !RadiusLeftTop))
{ g.FillRectangle(GetFillColor(), 0, Height - 1 - RectSize, RectSize, RectSize);
g.DrawLine(pen, Width - 1, 1, Width - 1, Height - 2); }
}
}
if (!ShowRectBottom) if (!ShowRectRight && !ShowRectBottom)
{ {
if (!ShowRadius || (!RadiusLeftBottom && !RadiusRightBottom)) if (!ShowRadius || (!RadiusLeftBottom && !RadiusLeftTop))
{ g.FillRectangle(GetFillColor(), Width - 1 - RectSize, Height - 1 - RectSize, RectSize, RectSize);
g.DrawLine(pen, 1, Height - 1, Width - 2, Height - 1);
}
}
if (!ShowRectLeft && !ShowRectTop)
{
if (!ShowRadius || (!RadiusLeftBottom && !RadiusLeftTop))
g.DrawLine(pen, 0, 0, 0, 1);
}
if (!ShowRectRight && !ShowRectTop)
{
if (!ShowRadius || (!RadiusLeftBottom && !RadiusLeftTop))
g.DrawLine(pen, Width - 1, 0, Width - 1, 1);
}
if (!ShowRectLeft && !ShowRectBottom)
{
if (!ShowRadius || (!RadiusLeftBottom && !RadiusLeftTop))
g.DrawLine(pen, 0, Height - 1, 0, Height - 2);
}
if (!ShowRectRight && !ShowRectBottom)
{
if (!ShowRadius || (!RadiusLeftBottom && !RadiusLeftTop))
g.DrawLine(pen, Width - 1, Height - 1, Width - 1, Height - 2);
}
} }
} }
@ -561,8 +586,7 @@ namespace Sunny.UI
/// <param name="path">路径</param> /// <param name="path">路径</param>
protected virtual void OnPaintRect(Graphics g, GraphicsPath path) protected virtual void OnPaintRect(Graphics g, GraphicsPath path)
{ {
Color color = GetRectColor(); g.DrawPath(GetRectColor(), path, true, RectSize);
g.DrawPath(color, path);
PaintRectDisableSides(g); PaintRectDisableSides(g);
} }
@ -593,11 +617,18 @@ namespace Sunny.UI
/// </summary> /// </summary>
protected Color rectColor = UIStyles.GetStyleColor(UIStyle.Blue).RectColor; protected Color rectColor = UIStyles.GetStyleColor(UIStyle.Blue).RectColor;
protected bool fillColorGradient = false;
/// <summary> /// <summary>
/// 填充颜色 /// 填充颜色
/// </summary> /// </summary>
protected Color fillColor = UIStyles.GetStyleColor(UIStyle.Blue).ButtonFillColor; protected Color fillColor = UIStyles.GetStyleColor(UIStyle.Blue).ButtonFillColor;
/// <summary>
/// 填充颜色
/// </summary>
protected Color fillColor2 = UIStyles.GetStyleColor(UIStyle.Blue).ButtonFillColor;
/// <summary> /// <summary>
/// 字体颜色 /// 字体颜色
/// </summary> /// </summary>
@ -810,6 +841,20 @@ namespace Sunny.UI
} }
} }
/// <summary>
/// 设置填充颜色
/// </summary>
/// <param name="value">颜色</param>
protected void SetFillColor2(Color value)
{
if (fillColor2 != value)
{
fillColor2 = value;
_style = UIStyle.Custom;
Invalidate();
}
}
/// <summary> /// <summary>
/// 设置字体颜色 /// 设置字体颜色
/// </summary> /// </summary>

View File

@ -20,6 +20,7 @@
* 2020-04-25: V2.2.4 * 2020-04-25: V2.2.4
* 2021-05-09: V3.0.3 * 2021-05-09: V3.0.3
* 2021-09-03: V3.0.6 * 2021-09-03: V3.0.6
* 2021-12-11: V3.0.9
******************************************************************************/ ******************************************************************************/
using System; using System;
@ -264,6 +265,53 @@ namespace Sunny.UI
} }
} }
private bool fillColorGradient;
[Description("填充颜色渐变"), Category("SunnyUI")]
[DefaultValue(false)]
public bool FillColorGradient
{
get => fillColorGradient;
set
{
if (fillColorGradient != value)
{
fillColorGradient = value;
Invalidate();
}
}
}
/// <summary>
/// 设置填充颜色
/// </summary>
/// <param name="value">颜色</param>
protected void SetFillColor2(Color value)
{
if (fillColor2 != value)
{
fillColor2 = value;
_style = UIStyle.Custom;
Invalidate();
}
}
/// <summary>
/// 填充颜色
/// </summary>
protected Color fillColor2 = UIStyles.GetStyleColor(UIStyle.Blue).ButtonFillColor;
/// <summary>
/// 填充颜色,当值为背景色或透明色或空值则不填充
/// </summary>
[Description("填充颜色"), Category("SunnyUI")]
[DefaultValue(typeof(Color), "80, 160, 255")]
public Color FillColor2
{
get => fillColor2;
set => SetFillColor2(value);
}
protected void SetFillDisableColor(Color color) protected void SetFillDisableColor(Color color)
{ {
fillDisableColor = color; fillDisableColor = color;
@ -468,10 +516,25 @@ namespace Sunny.UI
{ {
Color color = GetFillColor(); Color color = GetFillColor();
if (RadiusSides == UICornerRadiusSides.None) if (fillColorGradient)
g.Clear(color); {
LinearGradientBrush br = new LinearGradientBrush(new Point(0, 0), new Point(0, Height), FillColor, FillColor2);
br.GammaCorrection = true;
if (RadiusSides == UICornerRadiusSides.None)
g.FillRectangle(br, ClientRectangle);
else
g.FillPath(br, path);
br.Dispose();
}
else else
g.FillPath(color, path); {
if (RadiusSides == UICornerRadiusSides.None)
g.Clear(color);
else
g.FillPath(color, path);
}
} }
protected virtual void AfterSetFillColor(Color color) protected virtual void AfterSetFillColor(Color color)
@ -521,7 +584,7 @@ namespace Sunny.UI
public virtual void SetStyleColor(UIBaseStyle uiColor) public virtual void SetStyleColor(UIBaseStyle uiColor)
{ {
fillColor = uiColor.PlainColor; fillColor2 = fillColor = uiColor.PlainColor;
rectColor = uiColor.RectColor; rectColor = uiColor.RectColor;
foreColor = uiColor.PanelForeColor; foreColor = uiColor.PanelForeColor;

View File

@ -74,6 +74,11 @@ namespace Sunny.UI
return edit; return edit;
} }
public void Clear()
{
edit.Clear();
}
public RichTextBox RichTextBox => edit; public RichTextBox RichTextBox => edit;
public override Color BackColor { get => edit.BackColor; set { edit.BackColor = base.BackColor = value; } } public override Color BackColor { get => edit.BackColor; set { edit.BackColor = base.BackColor = value; } }

View File

@ -1415,7 +1415,7 @@ namespace Sunny.UI
{ {
if (CloseAskString.IsValid()) if (CloseAskString.IsValid())
{ {
if (!this.ShowAskDialog(CloseAskString)) if (!this.ShowAskDialog(CloseAskString, false))
{ {
e.Cancel = true; e.Cancel = true;
} }

View File

@ -52,7 +52,6 @@ namespace Sunny.UI
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None; this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
this.Name = "UIForm"; this.Name = "UIForm";
this.Padding = new System.Windows.Forms.Padding(0, 35, 0, 0); this.Padding = new System.Windows.Forms.Padding(0, 35, 0, 0);
this.ShowIcon = false;
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "UIForm"; this.Text = "UIForm";
this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.UIForm_FormClosing); this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.UIForm_FormClosing);

View File

@ -117,6 +117,8 @@ namespace Sunny.UI
public virtual Color EditorBackColor => Color.White; public virtual Color EditorBackColor => Color.White;
public virtual Color ButtonFillColor2 => ButtonFillColor;
public virtual void LoadFromFile() public virtual void LoadFromFile()
{ {
} }
@ -535,24 +537,63 @@ namespace Sunny.UI
public class UIDarkBlueStyle : UIBaseStyle public class UIDarkBlueStyle : UIBaseStyle
{ {
public override UIStyle Name => UIStyle.DarkBlue; public override UIStyle Name => UIStyle.DarkBlue;
public override Color PrimaryColor => UIColor.DarkBlue; public override Color PrimaryColor => Color.FromArgb(30, 32, 135);
public override Color RegularColor => Color.FromArgb(120, 148, 182); public override Color RegularColor => Color.FromArgb(120, 148, 182);
public override Color SecondaryColor => Color.FromArgb(120, 148, 182); public override Color SecondaryColor => Color.FromArgb(120, 148, 182);
public override Color PlainColor => UIColor.LightGray; public override Color PlainColor => Color.FromArgb(30, 32, 135);
public override Color ButtonFillColor => UIColor.DarkBlue; public override Color ButtonFillColor => Color.FromArgb(2, 167, 240);
public override Color ButtonFillHoverColor => Color.FromArgb(190, 230, 253); public override Color ButtonFillColor2 => Color.FromArgb(6, 13, 192);
public override Color ButtonFillPressColor => Color.FromArgb(169, 217, 242); public override Color ButtonFillHoverColor => Color.FromArgb(128, 255, 255);
public override Color ButtonForeColor => Color.FromArgb(130, 130, 130); public override Color ButtonFillPressColor => Color.FromArgb(108, 255, 255);
public override Color ButtonForeHoverColor => Color.FromArgb(130, 130, 130); public override Color ButtonForeColor => Color.FromArgb(242, 242, 242);
public override Color ButtonForePressColor => Color.FromArgb(130, 130, 130); public override Color ButtonForeHoverColor => UIFontColor.Primary;
public override Color RectSelectedColor => RectPressColor; public override Color ButtonForePressColor => UIFontColor.Primary;
public override Color ButtonForeSelectedColor => ButtonForePressColor; public override Color RectSelectedColor => Color.FromArgb(128, 255, 255);
public override Color ButtonFillSelectedColor => ButtonFillPressColor; public override Color ButtonForeSelectedColor => UIFontColor.Primary;
public override Color RectColor => Color.FromArgb(130, 130, 130); public override Color ButtonFillSelectedColor => Color.FromArgb(128, 255, 255);
public override Color RectHoverColor => Color.FromArgb(130, 130, 130); public override Color RectColor => Color.FromArgb(128, 255, 255);
public override Color RectPressColor => Color.FromArgb(130, 130, 130); public override Color RectHoverColor => Color.FromArgb(128, 255, 255);
public override Color RectPressColor => Color.FromArgb(128, 255, 255);
public override Color LabelForeColor => UIFontColor.Plain;
public override Color DropDownControlColor => UIFontColor.Primary;
public override Color CheckBoxColor => UIColor.Blue;
public override Color TitleColor => Color.FromArgb(130, 130, 130); public override Color TitleColor => Color.FromArgb(130, 130, 130);
public override Color TitleForeColor => Color.White; public override Color TitleForeColor => Color.White;
public override Color LineForeColor => UIFontColor.Plain;
public override Color ContextMenuColor => UIColor.RegularGray;
public override Color GridStripeOddColor => UIColor.RegularGray;
public override Color GridSelectedColor => UIFontColor.Plain;
public override Color GridSelectedForeColor => UIColor.White;
public override Color ListItemSelectBackColor => UIColor.Blue;
public override Color ListItemSelectForeColor => UIColor.LightBlue;
public override Color ProgressIndicatorColor => UIColor.Blue;
public override Color ProcessBarFillColor => PlainColor;
public override Color ProcessBarForeColor => UIColor.RegularGray;
public override Color ScrollBarForeColor => UIColor.RegularGray;
public override Color SwitchActiveColor => UIColor.DarkBlue;
public override Color SwitchInActiveColor => UIFontColor.Plain;
public override Color SwitchFillColor => Color.White;
public override Color TrackBarForeColor => UIColor.Blue;
public override Color TrackBarRectColor => UIColor.Blue;
public override Color TrackDisableColor => Color.Silver;
public override Color TreeViewSelectedColor => UIFontColor.Secondary;
public override Color TreeViewHoverColor => UIFontColor.Plain;
} }
public class UIBlackStyle : UIBaseStyle public class UIBlackStyle : UIBaseStyle