0

在我的应用程序中,我想添加工具提示。配置工具提示后,我希望该选项区分激活工具提示的标签以显示适当的文本,因此在工具提示功能中我尝试这样做但出现错误:“类型'Accessibility.IAccessible ' 在未引用的程序集中定义。您必须添加对程序集的引用 'Accessibility, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"

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

2 回答 2

2

来自 MSDN

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

因此,您只需要使用项目引用添加此引用。

当然PopupEventArgs包含为其绘制工具提示的控件,因此您可以简单地使用e.AssociatedControl.Name

于 2012-10-19T15:43:25.077 回答
0

您不需要引用 AccessibleObject。您只需要获取 AssociatedControl 的名称,如下所示:

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

至于您的子问题,要动态设置工具提示文本,您可以尝试以下操作:

        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 事件再次被触发

干杯

于 2012-10-19T16:08:14.187 回答