From 63c57882542a27b9c7bfb80a2a5b207e14aa0359 Mon Sep 17 00:00:00 2001 From: Sunny Date: Sat, 27 Jan 2024 20:42:35 +0800 Subject: [PATCH] =?UTF-8?q?*=20UIComboBox:=20=E4=BF=AE=E5=A4=8D=E5=9C=A8?= =?UTF-8?q?=E7=AA=97=E4=BD=93=E6=9E=84=E9=80=A0=E5=87=BD=E6=95=B0=E8=AE=BE?= =?UTF-8?q?=E7=BD=AESelectedIndex=E6=8A=A5=E9=94=99=20*=20UIDropControl:?= =?UTF-8?q?=20=E4=BF=AE=E6=94=B9=E6=8C=89=E9=92=AE=E5=A4=A7=E5=B0=8F?= =?UTF-8?q?=E8=B0=83=E6=95=B4=E6=97=B6=EF=BC=8C=E6=B8=85=E9=99=A4=E6=8C=89?= =?UTF-8?q?=E9=92=AE=E7=9A=84=E4=BD=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SunnyUI/Controls/DropItem/UIDropControl.cs | 7 ++----- SunnyUI/Controls/UIComboBox.cs | 1 + SunnyUI/Controls/UIListBox.cs | 14 +++++++++++++- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/SunnyUI/Controls/DropItem/UIDropControl.cs b/SunnyUI/Controls/DropItem/UIDropControl.cs index 04843ece..cc1608aa 100644 --- a/SunnyUI/Controls/DropItem/UIDropControl.cs +++ b/SunnyUI/Controls/DropItem/UIDropControl.cs @@ -32,6 +32,7 @@ * 2023-10-26: V3.5.1 字体图标增加旋转角度参数SymbolRotate * 2023-12-18: V3.6.2 修复高度不随字体改变 * 2024-01-19: V3.6.3 下拉按钮可修改大小及位置 + * 2024-01-27: V3.6.3 修改按钮大小调整时,清除按钮的位置 ******************************************************************************/ using System; @@ -75,8 +76,6 @@ namespace Sunny.UI fillColor = Color.White; edit.BackColor = Color.White; MouseMove += UIDropControl_MouseMove; - - ControlBoxRect = new Rectangle(Width - 24, 0, 24, Height); } int lastEditHeight = -1; @@ -426,7 +425,6 @@ namespace Sunny.UI edit.Left = 4 + Padding.Left; edit.Width = Width - Padding.Left - Padding.Right - 4; - ControlBoxRect = new Rectangle(Width - 24, 0, 24, Height); } /// @@ -481,7 +479,7 @@ namespace Sunny.UI return; } - bool inControlBox = e.Location.InRect(ControlBoxRect); + bool inControlBox = e.Location.X > Width - Padding.Right; if (inControlBox != NeedDrawClearButton && Text.IsValid()) { NeedDrawClearButton = inControlBox; @@ -499,7 +497,6 @@ namespace Sunny.UI } } - Rectangle ControlBoxRect; protected bool showClearButton; protected override void OnGotFocus(EventArgs e) diff --git a/SunnyUI/Controls/UIComboBox.cs b/SunnyUI/Controls/UIComboBox.cs index c25cf73c..a6b17809 100644 --- a/SunnyUI/Controls/UIComboBox.cs +++ b/SunnyUI/Controls/UIComboBox.cs @@ -39,6 +39,7 @@ * 2023-07-03: V3.3.9 修改了几个对象的释放 * 2023-08-11: V3.4.1 Items.Clear后,DropDownStyle为DropDown时,不清空Text * 2023-12-26: V3.6.2 增加下拉界面的滚动条设置 + * 2024-01-27: V3.6.3 修复在窗体构造函数设置SelectedIndex报错 ******************************************************************************/ using System; diff --git a/SunnyUI/Controls/UIListBox.cs b/SunnyUI/Controls/UIListBox.cs index 143e8209..d14accae 100644 --- a/SunnyUI/Controls/UIListBox.cs +++ b/SunnyUI/Controls/UIListBox.cs @@ -616,9 +616,21 @@ namespace Sunny.UI public int SelectedIndex { get => listbox.SelectedIndex; - set => listbox.SelectedIndex = value; + set + { + if (value >= 0) + { + if (listbox != null && listbox.Items != null && listbox.Items.ContainsIndex(value)) + listbox.SelectedIndex = value; + } + else + { + listbox.SelectedIndex = value; + } + } } + [Browsable(false)] [DefaultValue(null)] public object SelectedItem