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.
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.
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.
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! }
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.
I had so much trouble with the builtin tooltip that I built my own with a timer and tracking MouseMoved.