本文介绍了如何创建一个突出显示中间选定文本c#win的列表。形成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我想创建一个列表,搜索并检索列表中与搜索条件匹配的所有数据(要搜索的文本可以出现在列表的字符串 start,middle,end ) b $ b 我想要的样本图像实现 现在,情况是我可以自己处理搜索部分但我不知道如何创建控件在c#win中突出显示列表中的匹配文本。 form 解决方案 为DrawItem添加一个事件处理程序 this .ComboBox1 = new ComboBox(); this .ComboBox1.DrawMode = System.Windows.Forms.DrawMode.OwnerDrawVariable; this .ComboBox1.DrawItem + = new DrawItemEventHandler(ComboBox1_DrawItem); private void ComboBox1_DrawItem(对象发件人, System.Windows.Forms.DrawItemEventArgs e) { // 使用e.Graphics属性绘制自己的文本 // // e.Graphics.DrawString(...)); } 这里有一个MSDN示例:ComboBox.DrawItem I want to create a list that searches and retrieves all the data in list which is matching the searching criteria (the text to search can appears anywhere in the list's string start,middle,end)Sample Image Of What I Want To AchieveNow, the situation is i can handle the searching part myself but i dont know how to create control which highlights the matched text in the list in c# win. form 解决方案 Add one event handler for DrawItemthis.ComboBox1 = new ComboBox();this.ComboBox1.DrawMode = System.Windows.Forms.DrawMode.OwnerDrawVariable;this.ComboBox1.DrawItem += new DrawItemEventHandler(ComboBox1_DrawItem);private void ComboBox1_DrawItem(object sender, System.Windows.Forms.DrawItemEventArgs e){ // use e.Graphics property to draw your own text // // e.Graphics.DrawString(...));}There is a MSDN example here: ComboBox.DrawItem 这篇关于如何创建一个突出显示中间选定文本c#win的列表。形成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 10-24 09:03