From 655c09817735bc4b60124bf511f109a6872d8b12 Mon Sep 17 00:00:00 2001 From: Sunny Date: Thu, 3 Nov 2022 16:49:45 +0800 Subject: [PATCH] =?UTF-8?q?*=20UIComboBox:=20=E8=BF=87=E6=BB=A4=E6=97=B6?= =?UTF-8?q?=E5=88=A0=E9=99=A4=E5=AD=97=E7=AC=A6=E4=B8=B2=E5=89=8D=E9=9D=A2?= =?UTF-8?q?=E3=80=81=E5=90=8E=E9=9D=A2=E7=9A=84=E7=A9=BA=E6=A0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SunnyUI/Controls/UIComboBox.cs | 13 ++++++++++-- SunnyUI/Controls/UINavMenu.cs | 36 ++++++++++++++++++++++++++++++---- 2 files changed, 43 insertions(+), 6 deletions(-) diff --git a/SunnyUI/Controls/UIComboBox.cs b/SunnyUI/Controls/UIComboBox.cs index 64296317..40ee39f8 100644 --- a/SunnyUI/Controls/UIComboBox.cs +++ b/SunnyUI/Controls/UIComboBox.cs @@ -30,6 +30,7 @@ * 2022-05-04: V3.1.8 过滤时修复ValueMember绑定值的显示 * 2022-05-24: V3.1.9 Selceted=-1,清除文本 * 2022-08-25: V3.2.3 下拉框边框可设置颜色 + * 2022-11-03: V3.2.6 过滤时删除字符串前面、后面的空格 ******************************************************************************/ using System; @@ -330,6 +331,10 @@ namespace Sunny.UI if (Text.IsValid()) { + string filterText = Text; + if (TrimFilter) + filterText = filterText.Trim(); + filterForm.ListBox.Items.Clear(); filterList.Clear(); @@ -337,7 +342,7 @@ namespace Sunny.UI { foreach (var item in Items) { - if (item.ToString().Contains(Text)) + if (item.ToString().Contains(filterText)) { filterList.Add(item.ToString()); if (filterList.Count > FilterMaxCount) break; @@ -350,7 +355,7 @@ namespace Sunny.UI { for (int i = 0; i < Items.Count; i++) { - if (GetItemText(dataManager.List[i]).ToString().Contains(Text)) + if (GetItemText(dataManager.List[i]).ToString().Contains(filterText)) { filterList.Add(dataManager.List[i]); if (filterList.Count > FilterMaxCount) break; @@ -374,6 +379,10 @@ namespace Sunny.UI } } + [DefaultValue(false)] + [Description("过滤时删除字符串前面、后面的空格"), Category("SunnyUI")] + public bool TrimFilter { get; set; } + public void HideFilterForm() { if (FilterItemForm.Visible) diff --git a/SunnyUI/Controls/UINavMenu.cs b/SunnyUI/Controls/UINavMenu.cs index 5472dbda..6716ec76 100644 --- a/SunnyUI/Controls/UINavMenu.cs +++ b/SunnyUI/Controls/UINavMenu.cs @@ -91,6 +91,32 @@ namespace Sunny.UI selectedHighColor = UIStyles.Blue.NavMenuMenuSelectedColor; } + private int scrollBarWidth = 0; + + [DefaultValue(0), Category("SunnyUI"), Description("垂直滚动条宽度,最小为原生滚动条宽度")] + public int ScrollBarWidth + { + get => scrollBarWidth; + set + { + scrollBarWidth = value; + SetScrollInfo(); + } + } + + private int scrollBarHandleWidth = 6; + + [DefaultValue(6), Category("SunnyUI"), Description("垂直滚动条滑块宽度,最小为原生滚动条宽度")] + public int ScrollBarHandleWidth + { + get => scrollBarHandleWidth; + set + { + scrollBarHandleWidth = value; + if (Bar != null) Bar.FillWidth = value; + } + } + /// /// 禁止控件跟随窗体缩放 /// @@ -663,7 +689,7 @@ namespace Sunny.UI if (TreeNodeSymbols.ContainsKey(e.Node) && TreeNodeSymbols[e.Node].Count > 0) { - int symbolRight = Width - (ScrollBarVisible ? ScrollBarInfo.VerticalScrollBarWidth() : 0) - 3; + int symbolRight = Width - (ScrollBarVisible ? Bar.Width : 0) - 3; if (e.Node.Nodes.Count > 0) symbolRight -= 32; int firstLeft = symbolRight - TreeNodeSymbols[e.Node].Count * 32; @@ -680,7 +706,7 @@ namespace Sunny.UI if (TreeNodeSymbols.ContainsKey(e.Node) && TreeNodeSymbols[e.Node].Count > 0) { - int symbolRight = Width - (ScrollBarVisible ? ScrollBarInfo.VerticalScrollBarWidth() : 0) - 3; + int symbolRight = Width - (ScrollBarVisible ? Bar.Width : 0) - 3; if (e.Node.Nodes.Count > 0) symbolRight -= 32; int firstLeft = symbolRight - TreeNodeSymbols[e.Node].Count * 32; @@ -729,7 +755,7 @@ namespace Sunny.UI { SizeF tipsSize = e.Graphics.MeasureString(MenuHelper.GetTipsText(e.Node), TempFont); float sfMax = Math.Max(tipsSize.Width, tipsSize.Height) + 1; - float tipsLeft = Width - (ScrollBarVisible ? ScrollBarInfo.VerticalScrollBarWidth() : 0) - sfMax - sfMax; + float tipsLeft = Width - (ScrollBarVisible ? Bar.Width : 0) - sfMax - sfMax; if (e.Node.Nodes.Count > 0) tipsLeft -= 24; float tipsTop = e.Bounds.Y + (ItemHeight - sfMax) / 2; @@ -829,7 +855,7 @@ namespace Sunny.UI if (e.Node != null && TreeNodeSymbols.ContainsKey(e.Node) && TreeNodeSymbols[e.Node].Count > 0) { - int symbolRight = Width - (ScrollBarVisible ? ScrollBarInfo.VerticalScrollBarWidth() : 0) - 3; + int symbolRight = Width - (ScrollBarVisible ? Bar.Width : 0) - 3; if (e.Node.Nodes.Count > 0) symbolRight -= 32; int firstLeft = symbolRight - TreeNodeSymbols[e.Node].Count * 32; if (e.X >= firstLeft && e.X < symbolRight) @@ -910,10 +936,12 @@ namespace Sunny.UI return; } + int barWidth = Math.Max(ScrollBarInfo.VerticalScrollBarWidth(), ScrollBarWidth); var si = ScrollBarInfo.GetInfo(Handle); Bar.Maximum = si.ScrollMax; Bar.Visible = si.ScrollMax > 0 && si.nMax > 0 && si.nPage > 0; Bar.Value = si.nPos; + Bar.Width = barWidth + 1; Bar.BringToFront(); if (ScrollBarVisible != Bar.Visible)