gpt4 book ai didi

c# - 在非焦点 ToolStripItem 上显示工具提示

转载 作者:太空狗 更新时间:2023-10-29 18:28:33 25 4
gpt4 key购买 nike

当您将鼠标悬停在 ToolStripItems 上时,即使它们所在的窗体不在焦点上,ToolStripItems 也会显示事件突出显示。但是,除非表单获得焦点,否则它们不会显示工具提示。我看过 ToolStrip 'click-though' hack .任何人都知道如何让 ToolStripButton 在其父窗体未处于焦点时显示其工具提示?

谢谢!

最佳答案

问题是像 ToolStripButton 或 ToolStripDropDownButton 这样的 ToolStrip“控件”不继承自 Control。现在我通过在用户将鼠标悬停在按钮上时聚焦 ToolStrip 来解决这个问题。按钮的 MouseHover 事件触发得太晚了——在“显示工具提示”代码运行之后,所以我扩展了 ToolStripDropDownButton 类并使用了我的新按钮。此方法适用于任何其他继承自 ToolStripItem 的类似按钮的类

public class ToolStripDropDownEx : ToolStripDropDownButton
{
public ToolStripDropDownEx(string text)
{
}

protected override void OnMouseHover(EventArgs e)
{
if (this.Parent != null)
Parent.Focus();
base.OnMouseHover(e);
}
}

关于c# - 在非焦点 ToolStripItem 上显示工具提示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/143058/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com