* UIComboBox: 修复在窗体构造函数设置SelectedIndex报错

* UIDropControl: 修改按钮大小调整时,清除按钮的位置
This commit is contained in:
Sunny 2024-01-27 20:42:35 +08:00
parent 882dbb3f40
commit 63c5788254
3 changed files with 16 additions and 6 deletions

View File

@ -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);
}
/// <summary>
@ -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)

View File

@ -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;

View File

@ -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