Windows Forms ToolTip will not re-appear after first use

后端 未结 9 1340
借酒劲吻你
借酒劲吻你 2020-12-03 13:42

I have a Windows Forms C# application where I would like to use a tooltip on one of the text boxes. I initialize the tool-tip in the constructor of the Form class, and it wo

9条回答
  •  南方客
    南方客 (楼主)
    2020-12-03 14:17

    I had a similar problem today. VS 2010 SP1 .Net 3.5
    After AutoPopDelay-Time the ToolTip do not show the Controls ToolTipText.
    Kevins solution is the only way to solve the problem.

    I encapsulate this in my own ToolTip class:

    public class ToolTip : System.Windows.Forms.ToolTip 
    {
        public ToolTip() : base() { }
    
        public ToolTip(System.ComponentModel.IContainer components) : base(components) { }
    
        public new void SetToolTip(System.Windows.Forms.Control ctl, string caption) 
        {
            ctl.MouseEnter -= new System.EventHandler(toolTip_MouseEnter);
            base.SetToolTip(ctl, caption);
            if(caption != string.Empty)
            ctl.MouseEnter += new System.EventHandler(toolTip_MouseEnter);
        }
    
        private void toolTip_MouseEnter(object sender, EventArgs e) 
        {
            this.Active = false;
            this.Active = true;
        }
    }
    

提交回复
热议问题