Premo36 / DML2.X

Doom Mod Loader 2.X - launcher and organizer for ZDoom-like sourceports
https://p36software.net
BSD 3-Clause "New" or "Revised" License
23 stars 2 forks source link

Make longer preset names still fully visible in the preset combobox #13

Closed Premo36 closed 2 years ago

Premo36 commented 2 years ago

Implement something like this code (taken from https://stackoverflow.com/questions/48573024/add-scrollbar-to-winforms-combobox/48573154) to make the preset list as large as the longest preset name so it's always visible.

ComboBox senderComboBox = (ComboBox)sender;
int width = senderComboBox.DropDownWidth;
Graphics g = senderComboBox.CreateGraphics();
Font font = senderComboBox.Font;
int vertScrollBarWidth =
    (senderComboBox.Items.Count > senderComboBox.MaxDropDownItems)
    ? SystemInformation.VerticalScrollBarWidth : 0;

int newWidth;
foreach (string s in ((ComboBox)sender).Items)
{
    newWidth = (int)g.MeasureString(s, font).Width
        + vertScrollBarWidth;
    if (width < newWidth)
    {
        width = newWidth;
    }
}
senderComboBox.DropDownWidth = width;