Nicolas Mossmann
Nicolas Mossmann

Reputation: 75

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);
        }
    }
}

Upvotes: 1

Views: 4915

Answers (4)

vlad
vlad

Reputation: 21

It`s old question, but answer is here:

  1. Set the ShowItemToolTips property of the button to true.
  2. Set the ToolStripButton.AutoToolTip property of the button to false.

The AutoToolTip property is true by default for ToolStripButton. ToolStripDropDownButton, and ToolStripSplitButton.

A ToolStripButton uses its Text property for the ToolTip text by default. Use this procedure to display custom text in a ToolStripButtonToolTip.

Upvotes: 1

Benjamin Gale
Benjamin Gale

Reputation: 13177

ToolStripButton derives from ToolStripItem which has a ToolTipText property.

As already explained, the ToolStripItem does not derive from the Control class so provides its own implementation to render tool tips. This post may help you with customising the tooltip.

Upvotes: 4

nawfal
nawfal

Reputation: 73163

Strangely enough, toolstripbutton class doesnt inherit from Control class unlike other System.Windows.Forms gui components. Perhaps in your code e.AssociatedControl is meant to be used with System.Windows.Forms controls. In short, I think MS hasnt decided to provide a tooltip for strip controls. I do not know your exact requirement, but for some alternative that might click, see this link.

Upvotes: 0

GrayFox374
GrayFox374

Reputation: 1782

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.

Upvotes: 0

Related Questions