这就是我为解决这个问题所做的工作,效果很好……
public class ImprovedComboBox : ComboBox
{
public ImprovedComboBox()
{
}
public object DataSource
{
get { return base.DataSource; }
set { base.DataSource = value; DetermineDropDownWidth(); }
}
public string DisplayMember
{
get { return base.DisplayMember; }
set { base.DisplayMember = value; DetermineDropDownWidth(); }
}
public string ValueMember
{
get { return base.ValueMember; }
set { base.ValueMember = value; DetermineDropDownWidth(); }
}
private void DetermineDropDownWidth()
{
int widestStringInPixels = 0;
foreach (Object o in Items)
{
string toCheck;
PropertyInfo pinfo;
Type objectType = o.GetType();</