Tooltip for Disabled button

SiddhuMuthu 6 Reputation points
2021-05-29T09:12:52.137+00:00

How to add Tooltip for a disabled button but not through any Mouse Events

Please let me know , how to add tooltip for a disabled button

Developer technologies C#
{count} vote

1 answer

Sort by: Most helpful
  1. Timon Yang-MSFT 9,606 Reputation points
    2021-05-31T02:15:31.6+00:00

    Please refer to the following code to enable tooltip for the disabled button:

     bool IsShown = false;  
            private void Form1_Load(object sender, System.EventArgs e)  
            {  
                toolTip1.AutoPopDelay = 5000;  
                toolTip1.InitialDelay = 1000;  
                toolTip1.ReshowDelay = 500;  
      
                toolTip1.ShowAlways = true;  
      
                toolTip1.SetToolTip(this.button1, "test button");  
            }  
      
      
            void Form1_MouseMove(object sender, MouseEventArgs e)  
            {  
                Control ctrl = this.GetChildAtPoint(e.Location);  
      
                if (ctrl != null)  
                {  
                    if (ctrl == this.button1 && !IsShown)  
                    {  
                        string tipstring = this.toolTip1.GetToolTip(this.button1);  
                        this.toolTip1.Show(tipstring, this.button1, this.button1.Width / 2, this.button1.Height / 2);  
                        IsShown = true;  
                    }  
                }  
                else  
                {  
                    this.toolTip1.Hide(this.button1);  
                    IsShown = false;  
                }  
            }  
            private void button1_Click(object sender, EventArgs e)  
            {  
                button1.Enabled = false;  
            }  
    

    I haven't found a way to do it without any Mouse events. It seems that Mouse_Move is necessary.

    If it were in WPF, it would be simpler.

    <Button x:Name="button" ToolTipService.ShowOnDisabled="True" Content="Button"/>  
    

    Problem displaying tooltip over a disabled control


    If the response is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.