question

KarthikeyanRamalingam-6696 avatar image
0 Votes"
KarthikeyanRamalingam-6696 asked TimonYang-MSFT commented

Tooltip for Disabled button

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

dotnet-csharp
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

@KarthikeyanRamalingam-6696
May I know if you have got any chance to check my reply?
If it doesn't suit your situation or you have any new ideas, please feel free to raise them and we can have more discussions.

0 Votes 0 ·

1 Answer

TimonYang-MSFT avatar image
0 Votes"
TimonYang-MSFT answered

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.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.