Combobox下拉框加深显示Combobox中text的值,取消原有的填充显示
2015-01-15 22:49
417 查看
在输入Combobox内的text的值后,点击下拉按钮,Combobox下拉框内的值的内容如果与text的值相同,则会加深显示,底色为蓝色。有时候,Combobox下拉框内容的值没有经过排序,在进行关联显示的时候,可能不会显示到我们想要的准确的值。比如说,Combobox的下拉框的内容如下
TestTestTest
TestTest
Test
TestTestTestTestTest
如果,在Combobox中输入Test,那么点击下拉框时,是“TestTestTest”这一栏加深显示,而不是我们所要的“Test”。
对于这种情况,以及我们想要修改默认的加深颜色和字体,可以采用一下的方法:
——————————————————————————————————————————————————————————————————
欢迎大神光临菜鸟博客,希望能得到各位大神在编码方面的指引,同时欢迎与我一样刚进入编程世界的朋友一起讨论学习!相信前进的道路上,有你们,编程世界会更加精彩!
TestTestTest
TestTest
Test
TestTestTestTestTest
如果,在Combobox中输入Test,那么点击下拉框时,是“TestTestTest”这一栏加深显示,而不是我们所要的“Test”。
对于这种情况,以及我们想要修改默认的加深颜色和字体,可以采用一下的方法:
private void Form0109_Load(object sender, EventArgs e) { DefineComboBox ac = new DefineComboBox(); ac.Location = new Point(100,30); var test3 = new List<string>(); test3.Add("TestTestTest"); test3.Add("TestTestTestTestTest"); test3.Add("Test"); test3.Add("TestTest"); test3.Add("TestTestTestTestTestTestTestTestTestTestTestTestTestTestTest"); ac.DataSource = test3; this.Controls.Add(ac); } class DefineComboBox : ComboBox { new public System.Windows.Forms.DrawMode DrawMode { get; set; } public Color HighlightColor { get; set; }//define the highlight color public DefineComboBox() { base.DrawMode = System.Windows.Forms.DrawMode.OwnerDrawFixed; this.HighlightColor = Color.LightBlue; this.DrawItem += new DrawItemEventHandler(DefineComboBox_DrawItem); } void DefineComboBox_DrawItem(object sender, DrawItemEventArgs e) { if (e.Index < 0) return; ComboBox combo = sender as ComboBox; string combotext = combo.Text; <span style="color:#ff0000;"><strong>int index = combo.FindStringExact(combotext); //if ((e.State & DrawItemState.Selected) == DrawItemState.Selected) if (e.Index == index)</strong></span> e.Graphics.FillRectangle(new SolidBrush(HighlightColor), e.Bounds); else e.Graphics.FillRectangle(new SolidBrush(combo.BackColor), e.Bounds); e.Graphics.DrawString(combo.Items[e.Index].ToString(), e.Font, new SolidBrush(Color.Black), new Point(e.Bounds.X, e.Bounds.Y)); e.DrawFocusRectangle(); } }
——————————————————————————————————————————————————————————————————
欢迎大神光临菜鸟博客,希望能得到各位大神在编码方面的指引,同时欢迎与我一样刚进入编程世界的朋友一起讨论学习!相信前进的道路上,有你们,编程世界会更加精彩!
相关文章推荐
- EasyUI使用combobox的下拉框,显示第一个option的值,而不是text的问题
- EXT学习之——获取下拉框combobox的值与显示名
- extGrid里ComboBox显示下拉框的值
- easyui-combobox下拉框滚动条不显示&Java中的中文排序
- easyui的combobox下拉框初始化默认值以及保持该值一直显示的方法
- winform中ComboBox实现text和value,使显示和值分开,重写text和value属性
- easyui combobox 隐藏显示,加载取消验证。
- extjs4 分页工具栏pagingtoolbar的每页显示数据combobox下拉框
- 在ComboBox下拉框数据中显示图片
- extjs combobox下拉框显示位置问题
- extjs combobox下拉框显示位置问题
- VC下ComboBox 不显示下拉框的困惑
- 28-Dialog点击选择确定,取消,显示在TextView中
- EXT.NET 选择ComboBox下拉框中的值,另外一个下拉框的显示状态跟着变化
- 【jQuery easyUI】easyui-combobox下拉框按钮隐藏或取消
- extjs combobox下拉框显示位置问题
- 可以显示横向ScrollBar的下拉框ComboBox
- extjs4 分页工具栏pagingtoolbar的每页显示数据combobox下拉框
- 如何取消jquery combobox 下拉框的数据
- C# WINFORM中的combobox.items.add实现像web开发那样,添加显示内容text和实际value值