C# Winform工具提示问题

C# Winform工具提示问题,c#,winforms,C#,Winforms,在我的应用程序中,我想添加工具提示。 配置工具提示后,我希望该选项能够区分激活工具提示的标签,以便显示适当的文本,因此在工具提示功能中,我尝试执行此操作,但出现错误:“类型'Accessibility.IAccessible'是在未引用的程序集中定义的。必须添加对程序集“可访问性,版本=4.0.0.0,区域性=中性,PublicKeyToken=b03f5f7f11d50a3a”的引用“ 因此,您只需要使用项目引用添加此引用 当然,包含为其绘制工具提示的控件,因此您只需使用e.Associat

在我的应用程序中,我想添加工具提示。 配置工具提示后,我希望该选项能够区分激活工具提示的标签,以便显示适当的文本,因此在工具提示功能中,我尝试执行此操作,但出现错误:“类型'Accessibility.IAccessible'是在未引用的程序集中定义的。必须添加对程序集“可访问性,版本=4.0.0.0,区域性=中性,PublicKeyToken=b03f5f7f11d50a3a”的引用“

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


当然,包含为其绘制工具提示的控件,因此您只需使用
e.AssociatedControl.Name

即可,无需引用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将导致弹出事件再次触发


干杯

为什么不直接选择e.AssociatedControl.Name?您是否尝试添加对它告诉您要添加的程序集的引用?(可访问性)我想问题是他是否需要获取对AccessibleObject的引用。e.AssociatedControl.Name工作正常,谢谢!顺便说一句,如果我想通过toolTip1\u弹出函数将新字符串添加到工具提示中,我该如何做(我只找到工具提示标题)
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;
                }
            }
        }