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

    效果图:

  • 相关阅读:
    洛谷 P1494 [国家集训队]小Z的袜子 /【模板】莫队
    洛谷 P2801 教主的魔法
    数据库三范式
    vi和vim三种常见模式
    linux目录结构的具体介绍
    Linux怎么用root用户登录
    虚拟机的网络连接的三种方式
    事务
    数据库存储引擎
    delete和truncate
  • 原文地址:https://www.cnblogs.com/xiaoqi742709106/p/4635832.html
Copyright © 2011-2022 走看看