我正在使用show方法手动在控件上显示System.Windows.Forms.Tooltip,但是如何检测是否当前正在显示提示信息?
如果需要更改显示方法以便找出答案,那也可以。
如果需要更改显示方法以便找出答案,那也可以。
if (!string.IsNullOrEmpty(myToolTip.GetToolTip(myControl))) { // 成功! }
GetToolTip
(在winforms中测试)仅检查是否为该Control
调用了SetToolTip
方法;如果是,则返回文本,无论工具提示是否显示。据我所见,GetToolTip
的返回值与是否调用了Show
之间没有关系。 - Xilconic我曾经遇到了内置工具提示的许多问题,因此我使用计时器和跟踪鼠标移动来构建了自己的工具提示。
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
}
}
}
使用这段代码来进行EnumWindows互操作包装。这有点像黑客技巧,如果Tommy的解决方案适用于您,那就好多了。
IsOpen
只是 WPF 工具提示上的一个属性,而不是 WinForms 工具提示上的。 - Xilconic