如何设置 ComboBox 下拉列表的高度或间距

ComboBox 的下拉列表部分总是很挤,看起不舒服,但是设置了 ItemHeight 没用,怎么办呢?

首先设置一个较大的 ItemHeight 值,比如 20;

然后设置 ComboBox 的 DrawMode 为 OwnerDrawVariable;

然后在 DrawItem 事件中实现如何代码:

[csharp] view plain copy
 
  1. private void ComboBox1_DrawItem(object sender, DrawItemEventArgs e)  
  2. {  
  3.     if (e.Index < 0)  
  4.     {  
  5.         return;  
  6.     }  
  7.     e.DrawBackground();  
  8.     e.DrawFocusRectangle();  
  9.     e.Graphics.DrawString(ComboBox1.Items[e.Index].ToString(), e.Font, new SolidBrush(e.ForeColor), e.Bounds.X, e.Bounds.Y + 3);  
  10. }  

ItemHeight 是设置项的高度,但只设置它没用,为什么呢?因为默认的 DrawMode 决定了它不会有用,所以我们将 DrawMode 设置为 OwnerDrawVariable;然后再自己写 DrawItem 事件处理程序,最后一个参数决定了文字顶端要下移,让文字在选项的中间,看起来舒服些。
 
 http://blog.csdn.net/smeller/article/details/7446582
原文地址:https://www.cnblogs.com/Echo529/p/6382254.html