标签:scroll rap source change each graphics tostring combobox ble
///适用combobox绑定datatable
private void comboBox_DataSourceChanged(object sender, EventArgs e)
{
ComboBox cbb = sender as ComboBox;
string s = "";
foreach (DataRow row in (cbb.DataSource as DataTable).Rows)
{
string str = row[cbb.DisplayMember].ToString();
if (s.Length < str.Length)
{
s = str;
}
}
cbb.DropDownWidth = (int)cbb.CreateGraphics().MeasureString(s, cbb.Font).Width
+ (cbb.Items.Count > cbb.MaxDropDownItems ? SystemInformation.VerticalScrollBarWidth : 0);
}
标签:scroll rap source change each graphics tostring combobox ble
原文地址:https://www.cnblogs.com/masiteyi/p/9955980.html