2009-06-02 100 views
4

我使用show方法在控件上手動顯示System.Windows.Forms.Tooltip,但是如何檢測當前是否顯示工具提示?檢測是否顯示工具提示?

如果我需要改變顯示它的方法,那很好。

+0

如果您使用.Net 3.0或3.5,則會出現IsOpen標誌。對於2.0框架,我猜ToolTip.Active會有所幫助。但不知道。 – danish 2009-06-02 14:06:33

+0

IsOpen只是WPF工具提示的一個屬性,而不是winforms工具提示。 – Xilconic 2014-02-10 12:54:59

+0

ToolTip.Active屬性與工具提示是否顯示無關。不過,你的代碼會設置它,直到你的代碼改變它。 – 2014-08-10 20:01:33

回答

9

你可以嘗試ToolTip.GetToolTip(控制),並檢查返回值不是一個空字符串,像這樣:

if (!string.IsNullOrEmpty(myToolTip.GetToolTip(myControl))) 
{ 
    // Victory! 
}
1

如果這是可能被顯示的唯一工具提示,使用湯米的解。

如果有你的控制範圍之外的提示,你可以列舉所有工具提示窗口,並檢查其中之一是

一)所示的表格/應用程序範圍內

B)

有點像這樣:

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

} 

使用this codeEnumWindows互操作包裝。 這是一個黑客的一點,如果湯米的解決方案適合你,它是很多更好。

2

我內置的工具提示非常麻煩,我用定時器和跟蹤MouseMoved來構建我自己的工具提示。