views:

496

answers:

4

I am manually displaying a System.Windows.Forms.Tooltip on a control using the show method, but how can I detect if a tooltip is currently shown?

If I need to change the method for showing it to find out, that is fine.

A: 

If you are using .Net 3.0 or 3.5, there is a flag IsOpen for that. For 2.0 framework, I guess ToolTip.Active would help. Not sure though.

danish
The IsOpen property is only on the WPF implementation - I need the winforms implementation which doesn't have that.Active doesn't state if the tooltip is visible or not, just if it is active (i.e. attached and ready to be shown)
Robert MacLean
+3  A: 

You could try ToolTip.GetToolTip(control), and check if the returned value is not an empty string, like this:

if (!string.IsNullOrEmpty(myToolTip.GetToolTip(myControl)))
{
    // Victory!
}
Tommy Carlier
+1  A: 

If this is the only tooltip that can possibly be shown, use Tommy's solution.

If there are tooltips outside of your control, you could enumerate all Tooltip windows and check if one of them is

a) shown

b) within your form/applications bounds

somewhat like this:

Native.EnumWindows ew = new Native.EnumWindows();
ew.GetWindows();


foreach (EnumWindowsItem item in ew.Items)
{
    //find all windows forms tooltips currently visible
    if (item.ClassName.StartsWith("WindowsForms10.tooltips_class32") && item.Visible)
    {
     //check if tooltip is on within form bounds
     if (item.Location.X >= this.Location.X && item.Location.Y >= this.Location.Y && 
      item.Location.X <= this.Location.X + this.Width &&
      item.Location.Y <= this.Location.Y + this.Height)
     {
      //Tooltip currently shown within form bounds
     }
    }

}

using this code for the EnumWindows interop wrapper. It's a bit of a hack and if Tommy's solution works for you, it is much better.

Ben Schwehn
A: 

I had so much trouble with the builtin tooltip that I built my own with a timer and tracking MouseMoved.

Joshua