From 00897c5cc5d55a26c7df5642aeeb5287eaa1f699 Mon Sep 17 00:00:00 2001 From: Sunny Date: Thu, 3 Apr 2025 23:24:27 +0800 Subject: [PATCH] =?UTF-8?q?*=20UIBreadcrumb:=20=E5=A2=9E=E5=8A=A0SetItemCo?= =?UTF-8?q?lor=EF=BC=8C=E8=AE=BE=E7=BD=AE=E5=8D=95=E4=B8=AA=E8=8A=82?= =?UTF-8?q?=E7=82=B9=E9=A2=9C=E8=89=B2=EF=BC=8C=E5=8F=AF=E4=BB=A5=E7=94=A8?= =?UTF-8?q?RemoveItemColor=E7=A7=BB=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SunnyUI/Controls/UIBreadcrumb.cs | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/SunnyUI/Controls/UIBreadcrumb.cs b/SunnyUI/Controls/UIBreadcrumb.cs index 857d0492..cc61c310 100644 --- a/SunnyUI/Controls/UIBreadcrumb.cs +++ b/SunnyUI/Controls/UIBreadcrumb.cs @@ -22,6 +22,7 @@ * 2022-03-19: V3.1.1 重构主题配色 * 2023-05-12: V3.3.6 重构DrawString函数 * 2023-09-17: V3.4.2 增加Readonly,禁用鼠标点击,可通过代码设置ItemIndex + * 2025-04-03: V3.8.2 增加SetItemColor,设置单个节点颜色,可以用RemoveItemColor移除 ******************************************************************************/ using System; @@ -112,6 +113,20 @@ namespace Sunny.UI private readonly ConcurrentDictionary ClickArea = new ConcurrentDictionary(); + private readonly ConcurrentDictionary ItemsColor = new(); + + public void SetItemColor(int index, Color color) + { + ItemsColor[index] = color; + Invalidate(); + } + + public void RemoveItemColor(int index) + { + ItemsColor.TryRemove(index, out _); + Invalidate(); + } + /// /// 步骤个数 /// @@ -231,7 +246,9 @@ namespace Sunny.UI ClickArea[index] = pts; } - using Brush br = new SolidBrush(index <= ItemIndex ? SelectedColor : UnSelectedColor); + Color color = index <= ItemIndex ? SelectedColor : UnSelectedColor; + if (ItemsColor.TryGetValue(index, out var cc)) color = cc; + using Brush br = new SolidBrush(color); g.FillPolygon(br, points.ToArray()); g.DrawString(item.ToString(), Font, index <= ItemIndex ? ForeColor : UnSelectedForeColor,