* UIComboBox: 增加不显示过滤可以自动调整下拉框宽度

This commit is contained in:
Sunny 2022-11-13 10:30:24 +08:00
parent f2334b65c8
commit eaa30c9749

View File

@ -31,6 +31,7 @@
* 2022-05-24: V3.1.9 Selceted=-1
* 2022-08-25: V3.2.3
* 2022-11-03: V3.2.6
* 2022-11-13: V3.2.8
******************************************************************************/
using System;
@ -570,13 +571,43 @@ namespace Sunny.UI
UIComboBox_ButtonClick(this, EventArgs.Empty);
}
[DefaultValue(false)]
[Description("不显示过滤可以自动调整下拉框宽度"), Category("SunnyUI")]
public bool DropDownAutoWidth { get; set; }
private void UIComboBox_ButtonClick(object sender, EventArgs e)
{
if (!ShowFilter)
{
if (Items.Count > 0)
{
ItemForm.Show(this, new Size(DropDownWidth < Width ? Width : DropDownWidth, CalcItemFormHeight()));
int dropWidth = Width;
if (DropDownAutoWidth)
{
if (DataSource == null)
{
for (int i = 0; i < Items.Count; i++)
{
SizeF sf = GDI.MeasureString(Items[i].ToString(), Font);
dropWidth = Math.Max((int)sf.Width + ScrollBarInfo.VerticalScrollBarWidth() + 6, dropWidth);
}
}
else
{
for (int i = 0; i < Items.Count; i++)
{
SizeF sf = GDI.MeasureString(dropForm.ListBox.GetItemText(Items[i]), Font);
dropWidth = Math.Max((int)sf.Width + ScrollBarInfo.VerticalScrollBarWidth() + 6, dropWidth);
}
}
}
else
{
dropWidth = Math.Max(DropDownWidth, dropWidth);
}
ItemForm.Show(this, new Size(dropWidth, CalcItemFormHeight()));
}
}
else