Search code examples
c#winformscontrolstooltip

How to use tooltip on toolstripbutton


I'm trying to apply a tooltip to a toolstripbutton but it keeps giving me this error:

Operator '==' cannot be applied to operands of type 'System.Windows.Forms.Control' and 'System.Windows.Forms.ToolStripButton'

Any clue on how to solve this?

UPDATE:

private void toolTip1_Popup(object sender, PopupEventArgs e)
{
    if (e.AssociatedControl == tBtn1)
    {
        using (Font f = new Font("Tahoma", 9))
        {
            e.ToolTipSize = TextRenderer.MeasureText(
                toolTip1.GetToolTip(e.AssociatedControl), f);
        }
    }
}

Solution

  • UPDATE: After trying this out in a Winform project and not having success, I searched other threads on SO, this is one that may be helpful to you:

    Showing a tooltip on a non-focused ToolStripItem

    The problem with the first is you can't set it to the button directly, it doesn't inherit from Control, and the tooltip won't show up unless you're over the strip but not over a button.

    elsewhere

    I was trying to do the same thing and determined it was going to be pretty challenging and not worth it. The reason is that internally, the .NET code is specifically designed to only show the tooltip if the window is active - they are checking this at a Win32 level so its going to be hard to fake the code out.

    The user never accepted any of the answers as true, and it does seem at a glance that this may be a lot of work for little reward. Is this a project from scratch? If so, maybe you can do it using WPF, which is much more flexible than winforms.