From 452e9e6e156ed12c91db4d8b217b93c40e6bd414 Mon Sep 17 00:00:00 2001 From: Sunny Date: Mon, 2 Dec 2024 21:25:39 +0800 Subject: [PATCH] =?UTF-8?q?*=20UIScrollingText:=20=E5=81=9C=E6=AD=A2?= =?UTF-8?q?=E6=BB=9A=E5=8A=A8=E6=97=B6=EF=BC=8C=E5=8F=AF=E4=BB=A5=E8=AE=BE?= =?UTF-8?q?=E7=BD=AE=E9=BB=98=E8=AE=A4=E6=98=BE=E7=A4=BA=E4=BD=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SunnyUI/Controls/UIScrollingText.cs | 72 ++++++++++++++++------------- 1 file changed, 40 insertions(+), 32 deletions(-) diff --git a/SunnyUI/Controls/UIScrollingText.cs b/SunnyUI/Controls/UIScrollingText.cs index 6e617fdb..55c16b0d 100644 --- a/SunnyUI/Controls/UIScrollingText.cs +++ b/SunnyUI/Controls/UIScrollingText.cs @@ -21,6 +21,7 @@ * 2022-03-19: V3.1.1 重构主题配色 * 2023-02-23: V3.3.2 重写滚动逻辑 * 2023-05-12: V3.3.6 重构DrawString函数 + * 2024-12-02: V3.8.0 停止滚动时,可以设置默认显示位置 ******************************************************************************/ using System; @@ -153,41 +154,48 @@ namespace Sunny.UI /// 绘图路径 protected override void OnPaintFore(Graphics g, GraphicsPath path) { - Size sf = TextRenderer.MeasureText(Text, Font); - if (TextWidth != sf.Width) + if (Active) { - XPos = 0; - TextWidth = sf.Width; + Size sf = TextRenderer.MeasureText(Text, Font); + if (TextWidth != sf.Width) + { + XPos = 0; + TextWidth = sf.Width; + } + + if (ScrollingType == UIScrollingType.LeftToRight) + { + if (XPos + TextWidth > Width && TextWidth < Width - offset) + { + XPos1 = XPos - Width + offset; + g.DrawString(Text, Font, ForeColor, new Rectangle(XPos1, 0, Width, Height), ContentAlignment.MiddleLeft); + } + else + { + XPos1 = -TextWidth + offset; + } + + g.DrawString(Text, Font, ForeColor, new Rectangle(XPos, 0, Width, Height), ContentAlignment.MiddleLeft); + } + + if (ScrollingType == UIScrollingType.RightToLeft) + { + if (XPos < 0 && TextWidth < Width - offset) + { + XPos1 = Width + XPos - offset; + g.DrawString(Text, Font, ForeColor, new Rectangle(XPos1, 0, Width, Height), ContentAlignment.MiddleLeft); + } + else + { + XPos1 = Width - offset; + } + + g.DrawString(Text, Font, ForeColor, new Rectangle(XPos, 0, Width, Height), ContentAlignment.MiddleLeft); + } } - - if (ScrollingType == UIScrollingType.LeftToRight) + else { - if (XPos + TextWidth > Width && TextWidth < Width - offset) - { - XPos1 = XPos - Width + offset; - g.DrawString(Text, Font, ForeColor, new Rectangle(XPos1, 0, Width, Height), ContentAlignment.MiddleLeft); - } - else - { - XPos1 = -TextWidth + offset; - } - - g.DrawString(Text, Font, ForeColor, new Rectangle(XPos, 0, Width, Height), ContentAlignment.MiddleLeft); - } - - if (ScrollingType == UIScrollingType.RightToLeft) - { - if (XPos < 0 && TextWidth < Width - offset) - { - XPos1 = Width + XPos - offset; - g.DrawString(Text, Font, ForeColor, new Rectangle(XPos1, 0, Width, Height), ContentAlignment.MiddleLeft); - } - else - { - XPos1 = Width - offset; - } - - g.DrawString(Text, Font, ForeColor, new Rectangle(XPos, 0, Width, Height), ContentAlignment.MiddleLeft); + base.OnPaintFore(g, path); } }