从 .net winforms 中的工具提示中删除一个控件

remove one Control from ToolTip in .net winforms

在 winform 控件上设置工具提示就像在字典中添加内容:

ToolTip tt = new ToolTip();
tt.SetToolTip(control, "tooltip text");

将控件的文本设置为 null 将使应用程序不再在控件上显示工具提示:

tt.SetToolTip(control, null);

tt 必须持有对控件的引用。我想确保删除(和处置)控件不会导致内存泄漏,因此我需要从工具提示中删除对控件的引用。 设置为 null 会删除引用吗?还是 tt 会在其 'dictionary' 中以空值保留控制权?在后一种情况下如何永久删除这个控件? (我知道 tt.RemoveAll() 但我需要保留其他工具提示。)

你可以看看Tooltip.SetToolTip,
的源代码 看here for SetToolTipInternal
tools 是一个哈希表,传递 null 会调用 tools.Remove(control):

        ...
        bool exists = false;
        bool empty = false;

        if (tools.ContainsKey(control)) {
            exists = true;
        }

        if (info == null || String.IsNullOrEmpty(info.Caption)) {
            empty = true;
        }

        if (exists && empty) {
            tools.Remove(control);
        }
        ...