1

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);
        }
    }
}
Benjamin Gale
  • 12,977
  • 6
  • 62
  • 100

4 Answers4

4

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.

Community
  • 1
  • 1
Benjamin Gale
  • 12,977
  • 6
  • 62
  • 100
0

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.

Community
  • 1
  • 1
GrayFox374
  • 1,742
  • 9
  • 13
  • I updated the question with the code. The error I get now is: Cannot implicitly convert type 'System.Windows.Forms.ToolStripButton' to 'System.Windows.Forms.Control' – Nicolas Mossmann Jun 25 '12 at 15:01
  • In the absence of him posting the code that is actually causing the problem, I could only speculate a probable cause. I did ask him to update the code so I could update the answer. – GrayFox374 Jun 25 '12 at 15:09
  • @GrayFox374 so since now u understand his code, kindly update or remove the answer. I will cancel my -1 – nawfal Jun 25 '12 at 15:20
0

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.

nawfal
  • 70,104
  • 56
  • 326
  • 368
0

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.

vlad
  • 11
  • 2