zoukankan      html  css  js  c++  java
  • Winfrom 中如何实现combox 的列表自动显示ToolTip提示

    上边是实现后的结果,找了好长时间,才找到,做个记录。

    实现代码如下:

     ToolTip tt = null;
            ComboBox cb = null;
            private void Form1_Load(object sender, EventArgs e)
            {
                cb = new ComboBox();
                cb.Items.Insert(0,"第一");
                cb.Items.Insert(1,"第二");
                cb.Items.Insert(2,"第三");
                cb.Items.Insert(3,"第四");
                cb.DrawMode = DrawMode.OwnerDrawFixed;
                cb.DrawItem+=new DrawItemEventHandler(cb_DrawItem);
                cb.DropDownClosed+=new EventHandler(cb_DropDownClosed);
                this.Controls.Add(cb);
                cb.SelectedIndex = 1;
                tt = new ToolTip();
                tt.SetToolTip(cb, "zj");
            }
     void cb_DrawItem(object sender, System.Windows.Forms.DrawItemEventArgs e)
            {
                // 绘制背景
                e.DrawBackground();
                //绘制列表项目
                e.Graphics.DrawString(cb.Items[e.Index].ToString(), e.Font, System.Drawing.Brushes.Black, e.Bounds);
                //将高亮的列表项目的文字传递到toolTip1(之前建立ToolTip的一个实例)
                if ((e.State & DrawItemState.Selected) == DrawItemState.Selected)
                    tt.Show(cb.Items[e.Index].ToString(), cb, e.Bounds.X + e.Bounds.Width, e.Bounds.Y + e.Bounds.Height);
                e.DrawFocusRectangle();
            }
            void cb_DropDownClosed(object sender, EventArgs e)
            {
                tt.Hide(cb);
            }
    

      

  • 相关阅读:
    C艹函数与结构体
    c++ const 用法总结
    c++ 重载
    c++ 的makefile文件实例
    python3 异步模块asyncio
    C++ 面向对象 类成员函数this指针
    基于注释的Spring Security实战
    web 安全 初探 (正在更新)
    Spring dbcp连接池简单配置 示例
    Spring JDBC
  • 原文地址:https://www.cnblogs.com/zjBoy/p/2678431.html
Copyright © 2011-2022 走看看