diff --git a/Bin/net40/SunnyUI.dll b/Bin/net40/SunnyUI.dll index 7e570fd6..1de8e5a5 100644 Binary files a/Bin/net40/SunnyUI.dll and b/Bin/net40/SunnyUI.dll differ diff --git a/SunnyUI/Controls/UIControl.cs b/SunnyUI/Controls/UIControl.cs index d801f137..424cb41d 100644 --- a/SunnyUI/Controls/UIControl.cs +++ b/SunnyUI/Controls/UIControl.cs @@ -18,6 +18,7 @@ * * 2020-01-01: V2.2.0 增加文件说明 * 2020-04-25: V2.2.4 更新主题配置类 + * 2021-12-13: V3.0.9 边框线宽可设置1或者2 ******************************************************************************/ using System; diff --git a/SunnyUI/Controls/UINavMenu.cs b/SunnyUI/Controls/UINavMenu.cs index a638a8d8..988a7339 100644 --- a/SunnyUI/Controls/UINavMenu.cs +++ b/SunnyUI/Controls/UINavMenu.cs @@ -22,6 +22,7 @@ * 2021-06-14: V3.0.4 增加右侧图标 * 2021-08-07: V3.0.5 显示/隐藏子节点提示箭头 * 2021-08-27: V3.0.6 增加自定义TipsText显示的颜色 + * 2021-12-13: V3.0.9 选中项可设置背景色渐变 ******************************************************************************/ using System; @@ -29,6 +30,7 @@ using System.Collections.Concurrent; using System.Collections.Generic; using System.ComponentModel; using System.Drawing; +using System.Drawing.Drawing2D; using System.Windows.Forms; namespace Sunny.UI @@ -291,6 +293,53 @@ namespace Sunny.UI } } + private bool fillColorGradient; + + [Description("填充颜色渐变"), Category("SunnyUI")] + [DefaultValue(false)] + public bool SelectedColorGradient + { + get => fillColorGradient; + set + { + if (fillColorGradient != value) + { + fillColorGradient = value; + Invalidate(); + } + } + } + + /// + /// 设置填充颜色 + /// + /// 颜色 + private void SetFillColor2(Color value) + { + if (selectedColor2 != value) + { + selectedColor2 = value; + menuStyle = UIMenuStyle.Custom; + Invalidate(); + } + } + + /// + /// 填充颜色 + /// + private Color selectedColor2 = Color.FromArgb(36, 36, 36); + + /// + /// 填充颜色,当值为背景色或透明色或空值则不填充 + /// + [Description("填充颜色"), Category("SunnyUI")] + [DefaultValue(typeof(Color), "36, 36, 36")] + public Color SelectedColor2 + { + get => selectedColor2; + set => SetFillColor2(value); + } + private Color selectedHighColor = UIColor.Blue; /// @@ -372,6 +421,7 @@ namespace Sunny.UI BackColor = uiColor.BackColor; fillColor = uiColor.BackColor; selectedColor = uiColor.SelectedColor; + selectedColor2 = uiColor.SelectedColor2; foreColor = uiColor.UnSelectedForeColor; hoverColor = uiColor.HoverColor; secondBackColor = uiColor.SecondBackColor; @@ -556,8 +606,26 @@ namespace Sunny.UI SizeF sf = e.Graphics.MeasureString(e.Node.Text, Font); if (e.Node == SelectedNode) { - e.Graphics.FillRectangle((e.State & TreeNodeStates.Hot) != 0 ? HoverColor : SelectedColor, - new Rectangle(new Point(0, e.Node.Bounds.Y), new Size(Width, e.Node.Bounds.Height))); + if (SelectedColorGradient) + { + if ((e.State & TreeNodeStates.Hot) != 0) + { + e.Graphics.FillRectangle(HoverColor, new Rectangle(new Point(0, e.Node.Bounds.Y), new Size(Width, e.Node.Bounds.Height))); + + } + else + { + LinearGradientBrush br = new LinearGradientBrush(new Point(0, 0), new Point(0, e.Node.Bounds.Height), SelectedColor, SelectedColor2); + br.GammaCorrection = true; + e.Graphics.FillRectangle(br, new Rectangle(new Point(0, e.Node.Bounds.Y), new Size(Width, e.Node.Bounds.Height))); + br.Dispose(); + } + } + else + { + e.Graphics.FillRectangle((e.State & TreeNodeStates.Hot) != 0 ? HoverColor : SelectedColor, + new Rectangle(new Point(0, e.Node.Bounds.Y), new Size(Width, e.Node.Bounds.Height))); + } e.Graphics.DrawString(e.Node.Text, Font, SelectedForeColor, drawLeft, e.Bounds.Y + (ItemHeight - sf.Height) / 2.0f); e.Graphics.FillRectangle(SelectedHighColor, new Rectangle(0, e.Bounds.Y, 4, e.Bounds.Height)); diff --git a/SunnyUI/Controls/UIPanel.cs b/SunnyUI/Controls/UIPanel.cs index 1ac38b9b..6fee06b6 100644 --- a/SunnyUI/Controls/UIPanel.cs +++ b/SunnyUI/Controls/UIPanel.cs @@ -21,6 +21,7 @@ * 2021-05-09: V3.0.3 增加双缓冲,减少闪烁 * 2021-09-03: V3.0.6 支持背景图片显示 * 2021-12-11: V3.0.9 增加了渐变色 + * 2021-12-13: V3.0.9 边框线宽可设置1或者2 ******************************************************************************/ using System; @@ -371,7 +372,7 @@ namespace Sunny.UI if (IsDisposed) return; Rectangle rect = new Rectangle(0, 0, Width - 1, Height - 1); - GraphicsPath path = rect.CreateRoundedRectanglePath(radius, RadiusSides); + GraphicsPath path = rect.CreateRoundedRectanglePath(radius, RadiusSides, RectSize); //填充背景色 if (BackgroundImage == null && ShowFill && fillColor.IsValid()) @@ -406,8 +407,12 @@ namespace Sunny.UI protected virtual void OnPaintRect(Graphics g, GraphicsPath path) { - Color color = GetRectColor(); + g.DrawPath(GetRectColor(), path, true, RectSize); + PaintRectDisableSides(g); + } + private void PaintRectDisableSides(Graphics g) + { //IsRadius为False时,显示左侧边线 bool ShowRectLeft = RectSides.GetValue(ToolStripStatusLabelBorderSides.Left); //IsRadius为False时,显示上侧边线 @@ -426,89 +431,86 @@ namespace Sunny.UI //IsRadius为True时,显示右下圆角 bool RadiusRightBottom = RadiusSides.GetValue(UICornerRadiusSides.RightBottom); - if (RadiusSides == UICornerRadiusSides.None) - g.DrawRectangle(new Pen(color), 0, 0, Width - 1, Height - 1); - else - g.DrawPath(color, path); + var ShowRadius = RadiusSides > 0;//肯定少有一个角显示圆角 - using (Pen pen = new Pen(fillColor)) - using (Pen penR = new Pen(rectColor)) + if (!ShowRadius || (!RadiusLeftBottom && !RadiusLeftTop)) { - if (!ShowRadius || (ShowRadius && !RadiusLeftBottom && !RadiusLeftTop)) - { - g.DrawLine(penR, 0, 0, 0, Height - 1); - } + g.DrawLine(GetRectColor(), 0, 0, 0, Height - 1); + } - if (!ShowRadius || (ShowRadius && !RadiusRightTop && !RadiusLeftTop)) - { - g.DrawLine(penR, 0, 0, Width - 1, 0); - } + if (!ShowRadius || (!RadiusRightTop && !RadiusLeftTop)) + { + g.DrawLine(GetRectColor(), 0, 0, Width - 1, 0); + } - if (!ShowRadius || (ShowRadius && !RadiusRightTop && !RadiusRightBottom)) - { - g.DrawLine(penR, Width - 1, 0, Width - 1, Height - 1); - } + if (!ShowRadius || (!RadiusRightTop && !RadiusRightBottom)) + { + g.DrawLine(GetRectColor(), Width - 1, 0, Width - 1, Height - 1); + } - if (!ShowRectLeft) - { - if (!ShowRadius || (ShowRadius && !RadiusLeftBottom && !RadiusLeftTop)) - { - g.DrawLine(pen, 0, 1, 0, Height - 2); - } - } + if (!ShowRadius || (!RadiusLeftBottom && !RadiusRightBottom)) + { + g.DrawLine(GetRectColor(), 0, Height - 1, Width - 1, Height - 1); + } - if (!ShowRadius || (ShowRadius && !RadiusLeftBottom && !RadiusRightBottom)) + if (!ShowRectLeft) + { + if (!ShowRadius || (!RadiusLeftBottom && !RadiusLeftTop)) { - g.DrawLine(penR, 0, Height - 1, Width - 1, 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 (!ShowRectTop) + { + if (!ShowRadius || (!RadiusRightTop && !RadiusLeftTop)) { - if (!ShowRadius || (ShowRadius && !RadiusRightTop && !RadiusLeftTop)) - { - g.DrawLine(pen, 1, 0, Width - 2, 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 (!ShowRectRight) + { + if (!ShowRadius || (!RadiusRightTop && !RadiusRightBottom)) { - if (!ShowRadius || (ShowRadius && !RadiusRightTop && !RadiusRightBottom)) - { - g.DrawLine(pen, Width - 1, 1, Width - 1, Height - 2); - } + 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 (!ShowRectBottom) + { + if (!ShowRadius || (!RadiusLeftBottom && !RadiusRightBottom)) { - if (!ShowRadius || (ShowRadius && !RadiusLeftBottom && !RadiusRightBottom)) - { - g.DrawLine(pen, 1, Height - 1, Width - 2, 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 && !ShowRectTop) - { - if (!ShowRadius || (ShowRadius && !RadiusLeftBottom && !RadiusLeftTop)) - g.DrawLine(pen, 0, 0, 0, 1); - } + if (!ShowRectLeft && !ShowRectTop) + { + if (!ShowRadius || (!RadiusLeftBottom && !RadiusLeftTop)) + g.FillRectangle(GetFillColor(), 0, 0, RectSize, RectSize); + } - if (!ShowRectRight && !ShowRectTop) - { - if (!ShowRadius || (ShowRadius && !RadiusLeftBottom && !RadiusLeftTop)) - g.DrawLine(pen, Width - 1, 0, Width - 1, 1); - } + if (!ShowRectRight && !ShowRectTop) + { + if (!ShowRadius || (!RadiusLeftBottom && !RadiusLeftTop)) + g.FillRectangle(GetFillColor(), Width - 1 - RectSize, 0, RectSize, RectSize); + } - if (!ShowRectLeft && !ShowRectBottom) - { - if (!ShowRadius || (ShowRadius && !RadiusLeftBottom && !RadiusLeftTop)) - g.DrawLine(pen, 0, Height - 1, 0, Height - 2); - } + if (!ShowRectLeft && !ShowRectBottom) + { + if (!ShowRadius || (!RadiusLeftBottom && !RadiusLeftTop)) + g.FillRectangle(GetFillColor(), 0, Height - 1 - RectSize, RectSize, RectSize); + } - if (!ShowRectRight && !ShowRectBottom) - { - if (!ShowRadius || (ShowRadius && !RadiusLeftBottom && !RadiusLeftTop)) - g.DrawLine(pen, Width - 1, Height - 1, Width - 1, Height - 2); - } + if (!ShowRectRight && !ShowRectBottom) + { + if (!ShowRadius || (!RadiusLeftBottom && !RadiusLeftTop)) + g.FillRectangle(GetFillColor(), Width - 1 - RectSize, Height - 1 - RectSize, RectSize, RectSize); } } @@ -695,5 +697,28 @@ namespace Sunny.UI public delegate void OnTextAlignmentChange(object sender, ContentAlignment alignment); public event OnTextAlignmentChange TextAlignmentChange; + + private int rectSize = 1; + + /// + /// 边框颜色 + /// + [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(); + } + } + } } } \ No newline at end of file diff --git a/SunnyUI/Style/UIMenuStyle.cs b/SunnyUI/Style/UIMenuStyle.cs index 86d521e0..2c7c213f 100644 --- a/SunnyUI/Style/UIMenuStyle.cs +++ b/SunnyUI/Style/UIMenuStyle.cs @@ -52,9 +52,11 @@ namespace Sunny.UI public abstract UIMenuStyle Style { get; } public virtual Color BackColor => Color.FromArgb(56, 56, 56); public virtual Color SelectedColor => Color.FromArgb(36, 36, 36); + public virtual Color SelectedColor2 => Color.FromArgb(36, 36, 36); public virtual Color UnSelectedForeColor => Color.FromArgb(240, 240, 240); public virtual Color HoverColor => Color.FromArgb(76, 76, 76); public virtual Color SecondBackColor => Color.FromArgb(66, 66, 66); + public override string ToString() { return Style.DisplayText(); @@ -76,6 +78,7 @@ namespace Sunny.UI public override UIMenuStyle Style => UIMenuStyle.White; public override Color BackColor => Color.FromArgb(240, 240, 240); public override Color SelectedColor => Color.FromArgb(250, 250, 250); + public override Color SelectedColor2 => Color.FromArgb(250, 250, 250); public override Color UnSelectedForeColor => UIFontColor.Primary; public override Color HoverColor => Color.FromArgb(230, 230, 230); public override Color SecondBackColor => Color.FromArgb(235, 235, 235);