1 private void BindCombobox()
2 {
3 if (!GetConn.OpenConn())
4 {
5 return;
6 }
7 cboRestaurant.DataSource = DCLibrary.Current.RestaurantList;
8 cboRestaurant.ValueMember = "systemkey";
9 cboRestaurant.DisplayMember = "Description2";
10 Grap();
11
12 }
13 /// <summary>
14 /// 根据combobox 显示的文本动态设置【DropDownWidth】属性
15 /// </summary>
16 private void Grap() {
17 System.Drawing.Graphics g = cboRestaurant.CreateGraphics();
18 float width = 0;
19 foreach (DCLibrary.Model.RestaurantInfo s in cboRestaurant.Items)
20 {
21 if (width < g.MeasureString(s.Description2, cboRestaurant.Font).Width)
22 width = g.MeasureString(s.Description2, cboRestaurant.Font).Width;
23 }
24 if (width > cboRestaurant.DropDownWidth)
25 cboRestaurant.DropDownWidth = Convert.ToInt32(width);
26 g.Dispose();
27 }