How do I remove a tooltip currently bound to a control?

前端 未结 6 1907
北荒
北荒 2020-12-20 12:12

I\'m currently adding a tooltip to a label like so:

ToolTip LabelToolTip = new System.Windows.Forms.ToolTip();
LabelToolTip.SetToolTip(this.LocationLabel, te         


        
6条回答
  •  感情败类
    2020-12-20 12:23

    public class ToolTipHelper
    {
        private readonly Dictionary tooltips;
    
        /// 
        /// Constructor
        /// 
        public ToolTipHelper()
        {
            this.tooltips = new Dictionary();
        }
    
        /// 
        /// Key a tooltip by its control name
        /// 
        /// 
        /// 
        public ToolTip GetControlToolTip(string controlName)
        {
            if (tooltips.ContainsKey(controlName))
            {
                return tooltips[controlName];
            }
            else
            {
                ToolTip tt = new ToolTip();
                tooltips.Add(controlName, tt);
                return tt;
            }
        }
    }
    

    Usage:

    var tt = toolTips.GetControlToolTip("button1");
    tt.SetToolTip(button1, "This is my button1 tooltip");
    tt = toolTips.GetControlToolTip("button2");
    tt.SetToolTip(button2, "This is my button2 tooltip");
    

提交回复
热议问题