在winfrom中使用combobox怎么调整行距。在combobox属性里有ItemHeight属性可无法设置,它随着combobox.font.height变化。我希望在不调整font前提下设置ItemHeight的值。高手帮忙。。

解决方案 »

  1.   

    http://forums.microsoft.com/china/ShowPost.aspx?PostID=4223099&SiteID=15
      
    *****************************************************************************
    欢迎使用CSDN论坛专用阅读器 : CSDN Reader(附全部源代码) http://feiyun0112.cnblogs.com/
      

  2.   

    设置ItemDraw属性,查看msdn帮助。
      

  3.   

    先把DrawMode 设置为:OwnerDrawVariable,两个事件:comboBox1_DrawItem,comboBox1_MeasureItem 写你需要设置的颜色和高度
    后台代码:private void Form1_Load(object sender, EventArgs e)
            {
                this.comboBox1.Items.AddRange(new object[] { "123123", "5456456", "45456465" });
                this.comboBox1.DrawMode = DrawMode.OwnerDrawVariable;
            }
            private void comboBox1_DrawItem(object sender, DrawItemEventArgs e)
            {
                e.DrawBackground();
                Brush myBrush = Brushes.Black;
                switch (e.Index % 3)
                {
                    case 0:
                        myBrush = Brushes.Red;
                        break;
                    case 1:
                        myBrush = Brushes.Orange;
                        break;
                    case 2:
                        myBrush = Brushes.Purple;
                        break;
                }
                Font ft = new Font("瀹嬩綋", 12f);
                e.Graphics.DrawString(comboBox1.Items[e.Index].ToString(), ft, myBrush, e.Bounds, StringFormat.GenericDefault);
                e.DrawFocusRectangle();
            }
            private void comboBox1_MeasureItem(object sender, MeasureItemEventArgs e)
            {
                e.ItemHeight = 20;
            }
      

  4.   

     上面的一行代码:
     Font ft = new Font("瀹嬩綋", 12f);
    应该是Font ft = new Font("宋体", 12f);
      

  5.   

    谢谢javakiki 这个问题解决了。。当然谢谢也谢谢大家光临。