Controls - Do you extend the size of your ComboBoxes to show as many results as possible? (Windows Forms Only)
24/02/2017 1:38 AM by
When designing your form, it's a good idea to help your user whenever it's possible. So it's a good idea to extend your ComboBoxes to show as many results as possible to save your user from scrolling. Also, you should extend the width of the dropdown in order to show the longest items.
However, you should not extend your ComboBox without limit, normally the maximum number of items should be under 10 and the maximum width of the drop-down should be smaller than your hosting form.
- Figure: Bad Example - You have to scroll to see all the result, and the long results are cut off
- Figure: Good Example - The size of the drop down has been extended to allow user to see as much as possible
Changing the maximum items is easy, just include the following code in your form:
cbxOUList.MaxDropDownItems = cbxOUList.Items.Count;
Changing the drop down size is a bit of tricky
Graphics g = Graphics.FromHwnd(this.Handle);
SizeF stringSize = new SizeF();
stringSize = g.MeasureString(longString, cbx.Font, 600);
int adjustedSize = cbx.DropDownWidth;
if ( adjustedSize<(int)stringSize.Width )
adjustedSize = (int)stringSize.Width;
cbx.DropDownWidth = adjustedSize;
Do you feel this rule needs an update?