2012-10-19 133 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事件再次发射

干杯