C#自定义控件:鼠标悬停时触发的存放解释性文字信息的气泡

最近工作中遇到一个场景,对部分字段,在后面要放置一个问号图标,当鼠标悬停在该图标上时,要弹出解释性文字简要描述字段的功能。

新建一个自定义控件,里面包了一个PictureBox:

该控件C#代码如下:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace CustuomControl
{
    public partial class QuestionMark : UserControl
    {
        public QuestionMark()
        {
            InitializeComponent();

            //显示气泡
            toolTip.AutoPopDelay = 30000; 
            toolTip.IsBalloon = true;
            //toolTip.UseFading = true;
            string noticeInfo = NoticeDetail.GetNoticeInfo(NoticeCode);
            toolTip.SetToolTip(this.pcbQuestionMark, noticeInfo);
        }

        ToolTip toolTip = new ToolTip();     

        /// <summary>
        /// 提示信息代码
        /// </summary>
        private string _noticeCode;
        /// <summary>
        /// 提示信息代码
        /// </summary>
        public string NoticeCode
        {
            get
            {
                return _noticeCode;
            }
            set
            {
                _noticeCode = value;
                string noticeInfo = NoticeDetail.GetNoticeInfo(NoticeCode);
                toolTip.SetToolTip(this.pcbQuestionMark, noticeInfo);
            }
        }

    }
}

其中用到的NoticeDetail类,存储了提示信息编号与提示信息的关系。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CustuomControl
{
    public class NoticeDetail
    {
        public static string GetNoticeInfo(string noticeCode)
        {
            string result = "";
            if (!string.IsNullOrWhiteSpace(noticeCode))
            {
                switch (noticeCode)
                {
                    /** 所有的说明信息存储于此 */
                    case "100001": result = "英文名:Yue Buqun"; break;
                }
            }
            return result;
        }
    }
}

在使用控件时,可直接向NoticeCode属性赋值,也可以自己写代码手动赋值。

END

转载于:https://my.oschina.net/Tsybius2014/blog/681271

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值