Added auto size drop down extension for combo box

This commit is contained in:
Jaex 2021-04-25 20:49:40 +03:00
parent 6601b36932
commit 7f88c8c75f
4 changed files with 18 additions and 2 deletions

View file

@ -73,6 +73,7 @@ public void Add(object item)
public void AddRange(object[] items)
{
cbList.Items.AddRange(items);
cbList.AutoSizeDropDown();
}
}
}

View file

@ -680,6 +680,21 @@ public static void RefreshItems(this ComboBox cb)
typeof(ComboBox).InvokeMember("RefreshItems", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.InvokeMethod, null, cb, new object[] { });
}
public static void AutoSizeDropDown(this ComboBox cb)
{
int maxWidth = 0;
int verticalScrollBarWidth = cb.Items.Count > cb.MaxDropDownItems ? SystemInformation.VerticalScrollBarWidth : 0;
foreach (object item in cb.Items)
{
int tempWidth = TextRenderer.MeasureText(cb.GetItemText(item), cb.Font).Width + verticalScrollBarWidth;
if (tempWidth > maxWidth)
{
maxWidth = tempWidth;
}
}
cb.DropDownWidth = maxWidth;
}
public static void RefreshItem(this ListBox lb, int index)
{
typeof(ListBox).InvokeMember("RefreshItem", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.InvokeMethod, null, lb, new object[] { index });

View file

@ -1894,7 +1894,7 @@ internal static string ShapeManager_CreateToolbar_StartingStepValue {
}
/// <summary>
/// Looks up a localized string similar to Use type:.
/// Looks up a localized string similar to Step type:.
/// </summary>
internal static string ShapeManager_CreateToolbar_StepType {
get {

View file

@ -738,6 +738,6 @@ X: {4} Y: {5}</value>
<value>Menu icon size:</value>
</data>
<data name="ShapeManager_CreateToolbar_StepType" xml:space="preserve">
<value>Use type:</value>
<value>Step type:</value>
</data>
</root>