C# combobox 问题,菜鸟级问题 在winfrom中使用combobox怎么调整行距。在combobox属性里有ItemHeight属性可无法设置,它随着combobox.font.height变化。我希望在不调整font前提下设置ItemHeight的值。高手帮忙。。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 http://forums.microsoft.com/china/ShowPost.aspx?PostID=4223099&SiteID=15 *****************************************************************************欢迎使用CSDN论坛专用阅读器 : CSDN Reader(附全部源代码) http://feiyun0112.cnblogs.com/ 设置ItemDraw属性,查看msdn帮助。 先把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; } 上面的一行代码: Font ft = new Font("瀹嬩綋", 12f);应该是Font ft = new Font("宋体", 12f); 谢谢javakiki 这个问题解决了。。当然谢谢也谢谢大家光临。 access数据库 dll文件中,内嵌的Xml文件读取 写了个字符串查找与替换的小软件,共享一下 keybd event持续按住某一键 OnMouseOver 与 OnMouseMove 的问题 如何获得隐藏窗体句柄?(coredll.dll找不到) 搞晕了:通过普通html页面就无法上传文件?(Request.Files.Count=0) 在 WinForm 中. 怎么选中 DataGrid 控件中. 某一单元格 各位csdn的兄弟,我应不应该转到网站的后台开发,请给个建议 DataGird中怎么隐藏列??? gridview 求和 类之间的传递
*****************************************************************************
欢迎使用CSDN论坛专用阅读器 : CSDN Reader(附全部源代码) http://feiyun0112.cnblogs.com/
后台代码: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;
}
Font ft = new Font("瀹嬩綋", 12f);
应该是Font ft = new Font("宋体", 12f);