From cc1e8dadcc98c5934feca6beeb1dda6a6be12289 Mon Sep 17 00:00:00 2001 From: Sunny Date: Sun, 2 Jul 2023 16:57:24 +0800 Subject: [PATCH] =?UTF-8?q?*=20UIUserControl:=20=E6=B8=90=E5=8F=98?= =?UTF-8?q?=E8=89=B2=E5=A2=9E=E5=8A=A0=E6=96=B9=E5=90=91=E9=80=89=E6=8B=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SunnyUI/Controls/UIUserControl.cs | 39 ++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/SunnyUI/Controls/UIUserControl.cs b/SunnyUI/Controls/UIUserControl.cs index d2742852..9f55b27a 100644 --- a/SunnyUI/Controls/UIUserControl.cs +++ b/SunnyUI/Controls/UIUserControl.cs @@ -518,13 +518,50 @@ 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(); + } + } + } + + protected virtual void OnPaintFill(Graphics g, GraphicsPath path) { Color color = GetFillColor(); if (fillColorGradient) { - 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; if (RadiusSides == UICornerRadiusSides.None)