zoukankan      html  css  js  c++  java
  • Winform ComboBox控件高亮显示

     
                //重绘下拉表单窗口,需要在窗口设计代码中加入下面这一句  
                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();
            }
    
            //关闭列表时,同时关闭toolTip1的显示  
            private void kineticFileComboBox_DropDownClosed(object sender, System.EventArgs e)
            { toolTip1.Hide(cmdChannelName); }
            #endregion

    效果图:

  • 相关阅读:
    使用Power Shell 拉取项目源代码
    C# 读取excel数据到datatable
    C# 导出datatable数据到excel
    redis过一段时间连接不上
    windows10 docker volume
    通过端口查询到应用
    centos清理磁盘
    maven镜像加速
    IDEA常用插件
    java开发常用软件
  • 原文地址:https://www.cnblogs.com/xiaoqi742709106/p/4635832.html
Copyright © 2011-2022 走看看