Winform ComboBox控件高亮显示
生活随笔
收集整理的這篇文章主要介紹了
Winform ComboBox控件高亮显示
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
?
//重繪下拉表單窗口,需要在窗口設(shè)計代碼中加入下面這一句 this.cmdChannelName.DrawMode = System.Windows.Forms.DrawMode.OwnerDrawFixed;//下拉表單重繪事件 this.cmdChannelName.DrawItem += new System.Windows.Forms.DrawItemEventHandler(kineticFileComboBox_DrawItem);this.cmdChannelName.DropDownClosed += new System.EventHandler(kineticFileComboBox_DropDownClosed);#region ComboBox控件高亮顯示//[主程序中的代碼] private void kineticFileComboBox_DrawItem(object sender, System.Windows.Forms.DrawItemEventArgs e){// 繪制背景 e.DrawBackground();//繪制列表項目 e.Graphics.DrawString(cmdChannelName.Items[e.Index].ToString(), e.Font, System.Drawing.Brushes.Black, e.Bounds);//將高亮的列表項目的文字傳遞到toolTip1(之前建立ToolTip的一個實例) if ((e.State & DrawItemState.Selected) == DrawItemState.Selected)toolTip1.Show(cmdChannelName.Items[e.Index].ToString(), cmdChannelName, e.Bounds.X + e.Bounds.Width, e.Bounds.Y + e.Bounds.Height);e.DrawFocusRectangle();}//關(guān)閉列表時,同時關(guān)閉toolTip1的顯示 private void kineticFileComboBox_DropDownClosed(object sender, System.EventArgs e){ toolTip1.Hide(cmdChannelName); }#endregion?
效果圖:
?
轉(zhuǎn)載于:https://www.cnblogs.com/xiaoqi742709106/p/4635832.html
總結(jié)
以上是生活随笔為你收集整理的Winform ComboBox控件高亮显示的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 总结 | 如何测试你自己的 RubyGe
- 下一篇: 各种属性区别