2012-10-19 242 views
0

在我的應用程序中我想添加工具提示。 配置工具提示後,我想要區分激活工具提示的標籤以便在工具提示功能中顯示相應的文本,我嘗試去做,但出現錯誤:「The type'輔助功能.IAccessible '在未引用的程序集定義。你必須添加一個引用程序集' 輔助功能,版本= 4.0.0.0,文化=中性公鑰= b03f5f7f11d50a3a」Winform工具提示問題

private void toolTip1_Popup(object sender, PopupEventArgs e) 
{ 
    string st = e.AssociatedControl.AccessibilityObject.Parent.Name; 
} 
+0

爲什麼不直接去e.AssociatedControl.Name? –

+0

您是否嘗試添加對它指示的組件的引用? (Accessibility) – Pondidum

+0

我想問題是他是否需要獲取對AccessibleObject的引用,或者不。 –

回答

2

From MSDN

`To get or set the AccessibilityObject property, you must add a reference to the 
Accessibility assembly installed with the .NET Framework` 

所以你只需要添加這個參考ce使用項目參考。

當然PopupEventArgs包含了該工具提示繪製的控制,因此,你可以簡單地使用e.AssociatedControl.Name

0

你並不需要引用的AccessibleObject。所有你需要的是得到的名稱AssociatedControl的,就像這樣:

private void toolTip1_Popup(object sender, PopupEventArgs e) 
{ 
    string st = e.AssociatedControl.Name; 
} 

至於你subquestion,設置提示文本dinamically你可以嘗試這樣的事:

 private bool recursing; 
     private void toolTip1_Popup(object sender, PopupEventArgs e) 
     { 
      Control c = e.AssociatedControl as Control; 
      if (c != null) 
      { 
       if (!recursing) 
       { 
        recursing = true; 
        toolTip1.SetToolTip(c, "totototo"); 
        recursing = false; 
       } 
      } 
     } 

需要注意的是,我們有使用一個標誌,因爲調用SetToolTip會導致Popup事件再次發射

乾杯