Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WinForms tooltips not showing up

I have a WinForms application. Each form and user control sets up its tooltips as follows:

// in the control constructor
var toolTip = new ToolTip();
this.Disposed += (o, e) => toolTip.Dispose();
toolTip.SetToolTip(this.someButton, "...");
toolTip.SetToolTip(this.someCheckBox, "...");
...

However, the tooltips don't appear when I hover over the controls. Is this an appropriate way to use tooltips? Is there something that could be happening in another part of the application (e. g. listening to some event) that would stop tooltips from working?

Note that tooltips on my outer form's toolstrip buttons (which are configured via the button's tooltip property) do work as expected.

EDIT:

I've observed this more and I've noticed that sometimes the tooltip does show up, it is just extremely "flaky". Basically, sometimes when I mouse over a control it will show up very briefly and then flicker away. I can get it to show manually with .Show() and a long AutoPopDelay, but then it never disappears!

like image 694
ChaseMedallion Avatar asked Nov 28 '14 16:11

ChaseMedallion


People also ask

How do I add ToolTip in Winforms?

From within the designer: 1) From the ToolBox, drop a ToolTip control to your form. 2) Check the properties of this toolTip1 object to make sure Active is set to true. 3) Click on your button, and in its Property page, set the ToolTip on toolTip1 entry.

What is tooltips in C#?

In Windows Forms, the ToolTip represents a tiny pop-up box which appears when you place your pointer or cursor on the control and the purpose of this control is it provides a brief description about the control present in the windows form.


2 Answers

I faced similar issue when my tooltip was not showing up over the RichTextBox once in about 3-5 times it normally should. Even forcing it to show explicitly with toolTip.Show didn't help. Until I changed to the way mentioned by Shell - you have to tell where you want your tooltip to appear:

'Dim pnt As Point
pnt = control.PointToClient(Cursor.Position)
pnt.X += 10 ' Give a little offset
pnt.Y += 10 ' so tooltip will look neat
toolTip.Show(text, control, pnt)

This way my tooltip always appears when and where expected. Good luck!

like image 68
hypers Avatar answered Sep 22 '22 08:09

hypers


Your code seems ok to me. I couldnt find anything wrong in your code. But, it could be failed only when control is disabled. BTW, you can try another method like this. but, i would not like to suggest you to show the tooltip like this.

private void someButton_MouseEnter(...)
{
    toolTip.Show("Tooltip text goes here", (Button)sender);
}

You can also assign the location where tooltip should be displayed in .Show() method. there are some overloaded function that you can use. Read the msdn for more information about ToolTip.Show() method.

like image 33
Shell Avatar answered Sep 24 '22 08:09

Shell