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);
            }
    

      

  • 相关阅读:
    SpringData概述
    运行javac 报告javac不是内部或外部命令,但是运行java、java-version正常
    Spring Data JPA
    spring-data-jpa 介绍 复杂查询,包括多表关联,分页,排序等
    Thymeleaf使用说明
    Specifications查询
    OA项目_环境搭建
    anu
    anu
    anu
  • 原文地址:https://www.cnblogs.com/zjBoy/p/2678431.html
Copyright © 2011-2022 走看看