combobox下拉列表的内容长度问题
在MshFlexg中嵌套ComboBox的存在下拉列表,存在长度问题.请问各位大侠有何高招.
http://www.codeproject.com/KB/combobox/ComboBoxAutoWidth.aspx中,用VC写了如下代码
Adjust combo box drop down list width to longest string width
Introduction
This small snippet of code will show you how to automatically adjust the size of the drop down list of a combo box to fit the size of the longest string in its items.
Code
Step 1: Add an event handler for the DropDown event of the combo box. Call it AdjustWidthComboBox_DropDown for the sake of the following code.
Step 2: Add the following event handler code.
private void AdjustWidthComboBox_DropDown(object sender, System.EventArgs e)
{
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;
}
Explanation
请问各位大侠,还有其它的方法吗?