diff --git a/SunnyUI/Controls/UIButton.cs b/SunnyUI/Controls/UIButton.cs index 1884c84e..9599ccf3 100644 --- a/SunnyUI/Controls/UIButton.cs +++ b/SunnyUI/Controls/UIButton.cs @@ -28,6 +28,7 @@ * 2022-03-31: V3.1.2 是否显示浅色背景 * 2022-08-25: V3.2.3 增加同一个容器的相同GroupIndex的按钮控件的Selected单选 * 2023-05-12: V3.3.6 重构DrawString函数 + * 2023-07-02: V3.3.9 渐变色增加方向选择 ******************************************************************************/ using System; @@ -230,7 +231,26 @@ namespace Sunny.UI } else { - LinearGradientBrush br = new LinearGradientBrush(new Point(0, 0), new Point(0, Height), FillColor, FillColor2); + LinearGradientBrush br; + switch (fillColorGradientDirection) + { + case FlowDirection.LeftToRight: + br = new LinearGradientBrush(new Point(0, 0), new Point(Width, y: 0), FillColor, FillColor2); + break; + case FlowDirection.TopDown: + br = new LinearGradientBrush(new Point(0, 0), new Point(0, Height), FillColor, FillColor2); + break; + case FlowDirection.RightToLeft: + br = new LinearGradientBrush(new Point(Width, 0), new Point(0, y: 0), FillColor, FillColor2); + break; + case FlowDirection.BottomUp: + br = new LinearGradientBrush(new Point(0, Height), new Point(0, 0), FillColor, FillColor2); + break; + default: + br = new LinearGradientBrush(new Point(0, 0), new Point(0, Height), FillColor, FillColor2); + break; + } + br.GammaCorrection = true; g.FillPath(br, path); br.Dispose(); @@ -452,6 +472,23 @@ namespace Sunny.UI } } + private FlowDirection fillColorGradientDirection = FlowDirection.TopDown; + + [Description("填充颜色渐变方向"), Category("SunnyUI")] + [DefaultValue(FlowDirection.TopDown)] + public FlowDirection FillColorGradientDirection + { + get => fillColorGradientDirection; + set + { + if (fillColorGradientDirection != value) + { + fillColorGradientDirection = value; + Invalidate(); + } + } + } + /// /// 边框颜色 /// diff --git a/SunnyUI/Controls/UIUserControl.cs b/SunnyUI/Controls/UIUserControl.cs index 9f55b27a..397242f2 100644 --- a/SunnyUI/Controls/UIUserControl.cs +++ b/SunnyUI/Controls/UIUserControl.cs @@ -19,6 +19,7 @@ * 2022-04-02: V3.1.1 增加用户控件基类 * 2022-04-02: V3.1.2 默认设置AutoScaleMode为None * 2023-05-12: V3.3.6 重构DrawString函数 + * 2023-07-02: V3.3.9 渐变色增加方向选择 ******************************************************************************/ using System; @@ -535,7 +536,6 @@ namespace Sunny.UI } } - protected virtual void OnPaintFill(Graphics g, GraphicsPath path) { Color color = GetFillColor();