C#修改下拉框選項的高度

重寫ListBox.DrawItem事件處理,別忘記將ListBox.DrawMode 設置爲OwnerDrawVariable,ListBox.ItemHeight值改大一點,字體也適當放大一號。字體

 1         private void listBox1_DrawItem(object sender, DrawItemEventArgs e)
 2         {
 3             e.DrawBackground();
 4 
 5             e.DrawFocusRectangle();
 6 
 7             StringFormat strFmt = new System.Drawing.StringFormat();
 8 
 9             strFmt.Alignment = StringAlignment.Near; //文本水平居中
10 
11             strFmt.LineAlignment = StringAlignment.Center; //文本垂直居中
12 
13             e.Graphics.DrawString(listBox1.Items[e.Index].ToString(), e.Font, new SolidBrush(e.ForeColor), e.Bounds, strFmt);
14         }
相關文章
相關標籤/搜索