【问题标题】:Merge tooltip text functionality with status bar将工具提示文本功能与状态栏合并
【发布时间】:2011-04-04 16:05:19
【问题描述】:

我有一个包含多层容器嵌套(选项卡控件、表格、面板)的表单。最低级别的控件都有工具提示文本。工具提示有效(有时,但那是另一种蠕虫)。我想添加一小段代码,将 MDI 父级的状态栏文本更改为鼠标悬停的任何控件的工具提示文本。如果我在窗体上使用 MouseMove,它会在窗体上而不是任何子控件上拾取移动。如果我使用 MouseLeave,它只会拾取鼠标移动到最上面的子项(一个选项卡控件),而里面什么都没有。

我也许可以递归所有容器并添加 MouseLeave 处理程序,但这看起来很讨厌。将不胜感激有关完成此操作的最简单方法的提示。谢谢。

【问题讨论】:

    标签: .net winforms


    【解决方案1】:

    作为参考,这是我在表单的构造函数中执行的非理想递归解决方案:

            Action<Control> mouseListen = null;
            mouseListen = control =>
            {
                string toolText = toolTip.GetToolTip(control);
                if (toolText != "")
                {
                    control.MouseEnter += (sender, args) =>
                        { Program.MainForm.Status = toolText; };
                    control.MouseLeave += (sender, args) =>
                        { Program.MainForm.Status = Program.MainForm.DefaultStatus; };
                }
                foreach (Control child in control.Controls)
                    mouseListen(child);
            };
            mouseListen(this);
    

    【讨论】:

      猜你喜欢
      • 2011-02-20
      • 2016-03-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-05-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多