zoukankan      html  css  js  c++  java
  • Winform Combobox+Tooltip 扩展tips功能

     创建Windows服务

    using System;

    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Drawing;
    using System.Data;
    using System.Text;
    using System.Windows.Forms;
    using System.Runtime.InteropServices;
    using System.Threading;
    namespace QouShui.DLL.ComboBoxs
    {
        /// <summary>
        /// 支持显示提示框的combobox
        /// 在displayMember和valueMember外,增加一个tipMember,用于显示提示内容,理论上还可以增加多个tipMember
        /// </summary>
        public partial class ComboBoxWithToolTipAndDataSource : ComboBox 
        {
            public ComboBoxWithToolTipAndDataSource()
            {
                InitializeComponent();
                this.DropDown += new EventHandler(ComboBoxWithToolTipAndDataSource_DropDown);
                this.DropDownClosed += new EventHandler(ComboBoxWithToolTipAndDataSource_DropDownClosed);
                this.DrawItem += new DrawItemEventHandler(ComboBoxWithToolTipAndDataSource_DrawItem);
           
            }
            
           
            private string tipMember="";
            /// <summary>用于显示提示说明的列
            /// </summary>
            [System.ComponentModel.Description("用于显示提示说明的列")]
            public string TipMember
            {
                get
                {
                    return tipMember;
                }
                set
                {
                    tipMember = value;
                }
            }
            private void ComboBoxWithToolTipAndDataSource_DrawItem(object sender, DrawItemEventArgs e)
            {
                try
                {
                    e.DrawBackground();
                    DataTable dt = DataSource as DataTable;
                    if (dt != null)
                    {
                        if ((e.State & DrawItemState.Selected) == DrawItemState.Selected)
                        {
                            e.Graphics.DrawString(dt.Rows[e.Index][DisplayMember].ToString(), e.Font, SystemBrushes.HighlightText, e.Bounds);
                            if (tipMember.Length > 0)
                            {
                                tp.Show(dt.Rows[e.Index][TipMember].ToString(), this, e.Bounds.Width, e.Bounds.Y + Height);
                            }
                        }
                        else
                        {
                            e.Graphics.DrawString(dt.Rows[e.Index][DisplayMember].ToString(), e.Font, SystemBrushes.WindowText, e.Bounds);
                        }
                    }
                    else
                    {
                        DataView dv = DataSource as DataView;
                        if (dv == null)
                            return;
                        if ((e.State & DrawItemState.Selected) == DrawItemState.Selected)
                        {
                            e.Graphics.DrawString(dv[e.Index][DisplayMember].ToString(), e.Font, SystemBrushes.HighlightText, e.Bounds);
                            if (tipMember.Length > 0)
                                tp.Show(dv[e.Index][tipMember].ToString(), this, e.Bounds.Width, e.Bounds.Y + Height);
                        }
                        else
                        {
                            e.Graphics.DrawString(dv[e.Index][DisplayMember].ToString(), e.Font, new SolidBrush(e.ForeColor), e.Bounds);
                        }
                    }
                    e.DrawFocusRectangle();
                }
                catch
                {
                }
            }
            void ComboBoxWithToolTipAndDataSource_DropDownClosed(object sender, EventArgs e)
            {
                tp.Active = false ;
                
            }
            void ComboBoxWithToolTipAndDataSource_DropDown(object sender, EventArgs e)
            {
                tp.Active = true ;  
            }
            
            
        }
        
    }
     

     前台调用

    LoadData()
            {
                DataTable dt = new DataTable();
                dt.Columns.Add("名称");
                dt.Columns.Add("编号",typeof(int));
                dt.Columns.Add("说明");
                dt.Rows.Add(new object[] { "清明节", 0, "4月3日,三天" });
                dt.Rows.Add(new object[] { "劳动节", 1, "5月1日,七天" });
                dt.Rows.Add(new object[] { "国庆节", 2, "10月1日,8天" });
                comboBoxWithToolTipAndDataSource1.DataSource = dt;
                comboBoxWithToolTipAndDataSource1.DisplayMember = "名称";
                comboBoxWithToolTipAndDataSource1.ValueMember = "编号";
                comboBoxWithToolTipAndDataSource1.TipMember = "说明";
                comboBoxWithToolTipAndDataSource1.DropDownStyle = ComboBoxStyle.DropDownList;
                 

            } 

  • 相关阅读:
    BFS(从数字A变到数字B每次只能换一个数)
    BFS(数字a通过三种操作到数字B)
    dfs+bfs(三种路径问题)
    国际象棋跳马问题
    拓扑排序
    hadoop-hdfs、mapreduce学习随笔
    hive初探2_数据模型
    hive初探_框架组成、简单使用
    Scala学习笔记
    Scala安装
  • 原文地址:https://www.cnblogs.com/colder/p/2096430.html
Copyright © 2011-2022 走看看