WinForms tooltips not showing up

11,806

Solution 1

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!

Solution 2

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.

Solution 3

I wrote the following method to "propagate" ToolTips from parent controls (that have a tool tip set) to its child controls (unless they have their own overriding ToolTip).

It's designed to be dropped into the form or control you're starting with, but it could also just be turned into a static method where the "parent" argument is required.

/// <summary>Setting a toolTip on a custom control unfortunately doesn't set it on child
/// controls within its drawing area. This is a workaround for that.</summary>
private void PropagateToolTips(Control parent = null)
{
    parent = parent ?? this;
    string toolTip = toolTip1.GetToolTip(parent);
    if (toolTip == "")
        toolTip = null;
    foreach (Control child in parent.Controls)
    {
        // If the parent has a toolTip, and the child control does not
        // have its own toolTip set - set it to match the parent toolTip.
        if (toolTip != null && String.IsNullOrEmpty(toolTip1.GetToolTip(child)))
            toolTip1.SetToolTip(child, toolTip);
        // Recurse on the child control
        PropagateToolTips(child);
    }
}

Note that the behaviour is undefined if you're using more than one ToolTip instance to manage parent and child control toolTips.

Share:
11,806
ChaseMedallion
Author by

ChaseMedallion

Updated on June 04, 2022

Comments

  • ChaseMedallion
    ChaseMedallion almost 2 years

    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!

  • Elmue
    Elmue over 2 years
    I can confirm that this workaround works. This problem is an ugly Windows 10 bug. It is difficult to reproduce. It happens in one Form and in another Form with identical code it does not happen. Mostly the tooltip shows up once and then disappears forever. A very ugly Windows bug!