From b270317f3127292f886f1ed31cfb0c51a692647a Mon Sep 17 00:00:00 2001 From: Sunny Date: Sat, 26 Nov 2022 10:09:39 +0800 Subject: [PATCH] =?UTF-8?q?*=20UILine:=20=E6=B0=B4=E5=B9=B3=E6=96=B9?= =?UTF-8?q?=E5=90=91=E6=96=87=E5=AD=97=E4=B8=8D=E5=B1=85=E4=B8=AD=E6=97=B6?= =?UTF-8?q?=EF=BC=8C=E5=8F=AF=E8=AE=BE=E7=BD=AE=E7=BA=BF=E6=9D=A1=E6=B8=90?= =?UTF-8?q?=E5=8F=98=E8=89=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SunnyUI/Controls/UILine.cs | 52 +++++++++++++++++++++++++++++++++++--- 1 file changed, 48 insertions(+), 4 deletions(-) diff --git a/SunnyUI/Controls/UILine.cs b/SunnyUI/Controls/UILine.cs index c9b21834..79c34918 100644 --- a/SunnyUI/Controls/UILine.cs +++ b/SunnyUI/Controls/UILine.cs @@ -20,6 +20,7 @@ * 2022-01-05: V3.0.9 增加线的样式,支持透明背景 * 2022-01-10: V3.1.0 修复了文本为空不显示的问题 * 2022-03-19: V3.1.1 重构主题配色 + * 2022-11-26: V3.2.9 水平方向文字不居中时,可设置线条渐变色 ******************************************************************************/ using System; @@ -93,6 +94,7 @@ namespace Sunny.UI rectColor = uiColor.LineRectColor; foreColor = uiColor.LineForeColor; fillColor = uiColor.LineFillColor; + fillColor2 = uiColor.PanelFillColor2; } /// @@ -244,13 +246,29 @@ namespace Sunny.UI g.DrawLine(pen, x + sf.Width + 2, top, Width - 2 - Padding.Left - Padding.Right, top); break; default: - g.DrawLine(pen, Padding.Left, top, Width - 2 - Padding.Left - Padding.Right, top); + if (LineColorGradient) + { + using LinearGradientBrush br = new LinearGradientBrush(new Point(0, 0), new Point(Width, 0), LineColor, LineColor2); + g.FillRectangle(br, new Rectangle(Padding.Left, top, Width - 2 - Padding.Left - Padding.Right, LineSize)); + } + else + { + g.DrawLine(pen, Padding.Left, top, Width - 2 - Padding.Left - Padding.Right, top); + } break; } } else { - g.DrawLine(pen, Padding.Left, top, Width - 2 - Padding.Left - Padding.Right, top); + if (LineColorGradient) + { + using LinearGradientBrush br = new LinearGradientBrush(new Point(0, 0), new Point(Width, 0), LineColor, LineColor2); + g.FillRectangle(br, new Rectangle(Padding.Left, top, Width - 2 - Padding.Left - Padding.Right, LineSize)); + } + else + { + g.DrawLine(pen, Padding.Left, top, Width - 2 - Padding.Left - Padding.Right, top); + } } switch (startCap) @@ -323,14 +341,40 @@ namespace Sunny.UI } /// - /// 边框颜色 + /// 线颜色 /// - [Description("边框颜色"), Category("SunnyUI")] + [Description("线颜色"), Category("SunnyUI")] [DefaultValue(typeof(Color), "80, 160, 255")] public Color LineColor { get => rectColor; set => SetRectColor(value); } + + /// + /// 线颜色2 + /// + [Description("线颜色2"), Category("SunnyUI")] + [DefaultValue(typeof(Color), "243, 249, 255")] + public Color LineColor2 + { + get => fillColor2; + set => SetFillColor2(value); + } + + [Description("线颜色渐变"), Category("SunnyUI")] + [DefaultValue(false)] + public bool LineColorGradient + { + get => fillColorGradient; + set + { + if (fillColorGradient != value) + { + fillColorGradient = value; + Invalidate(); + } + } + } } } \ No newline at end of file