ComboBox.PreferredSize

  • Thread starter Thread starter Ethan Strauss
  • Start date Start date
E

Ethan Strauss

Hi,
In a C#.Net2.0 Winforms application I have some combo boxes. I ind these
boxes to enum values and then call
ComboBox.Size = ComboBox.PreferredSize:
But, the combo box is never wide enough to display long items! Isn't that
what PreferredSize is uspposed to give? Am I missing something or is there
another way to make sure that my comboboxes are wide enough to display all
the text in them?

Thanks!
Ethan
 
Hi,
  In a C#.Net2.0 Winforms application I have some combo boxes. I ind these
boxes to enum values and then call
ComboBox.Size = ComboBox.PreferredSize:
But, the combo box is never wide enough to display long items! Isn't that
what PreferredSize is uspposed to give?

It is not. Control.PreferredSize is about sizing of controls when they
are layed out automatically (using TableLayoutPanel/FlowLayoutPanel).
Am I missing something or is there another way to make sure that my comboboxes are wide enough to display all
the text in them?

You can use ComboBox.DropDownWidth to make the width of the dropdown
list larger to accomodate long strings; but there is no way that I
know of to make it auto-sizing. If you really need it, you can use
TextRenderer.MeasureText to measure width of all items, and update
DropDownWidth according to the measurements.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top