显示在非重点的ToolStripItem工具提示提示、重点、工具、ToolStripItem

2023-09-05 23:00:39 作者:岛森屿夏

ToolStripItems显示激活的高亮当你把鼠标移到他们,即使他们是在形式不在焦点。他们不这样做,但是,显示其工具提示,除非形式的重点。我已经看到了 ToolStrip的点击 - 尽管黑客 。任何人都知道如何使ToolStripButton显示其提示时,它的父窗体没有焦点?

ToolStripItems show Active highlighting when you mouse over them, even if the form they are in is not in focus. They do not, however, show their tooltips, unless the form is focused. I have seen the ToolStrip 'click-though' hack. Anyone know how to make a ToolStripButton show its tooltip when its parent form is not in focus?

谢谢!

推荐答案

问题是,ToolStrip的控制之类的ToolStripButton或ToolStripDropDownButton不从Control继承。现在我通过集中每当用户将鼠标悬停在一个按钮ToolStrip的解决了这个问题。按钮的MouseHover事件被激发太晚了 - 显示工具提示code就会被运行后,所以我延长了ToolStripDropDownButton类,并用我的新按钮。这种方法应该适用于任何其他的类似按钮的类自ToolStripItem继承

The problem is that the ToolStrip "controls" like ToolStripButton or ToolStripDropDownButton don't inherit from Control. For now I addressed the problem by focusing the ToolStrip whenever a user hovers over a button. The button's MouseHover event is fired too late -- after the "show tooltip" code would have been run, so I extended the ToolStripDropDownButton class and used my new button. This method should work for any of the other button-like classes inheriting from ToolStripItem

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

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