开发者

Merge tooltip text functionality with status bar

开发者 https://www.devze.com 2023-02-22 13:01 出处:网络
I have a form with several levels of container nesting (tab controls, tables, panels). The lowest-level controls all have tooltip text. The tooltip works (some of the time, but that\'s another can of

I have a form with several levels of container nesting (tab controls, tables, panels). The lowest-level controls all have tooltip text. The tooltip works (some of the time, but that's another can of worms). I'd like to add a small bit of code that changes the MDI parent's status bar text to equal the tooltip text of any control that the mouse is over. 开发者_运维技巧If I use MouseMove on the form, it picks up movement on the form but not on any of the child controls. If I use MouseLeave, it only picks up the mouse moving to the topmost child (a tab control) and nothing on the inside.

I might be able to recurse through all of the containers and add MouseLeave handlers, but that seems nasty. Hints on the simplest way to accomplish this would be appreciated. Thanks.


For reference, here is my non-ideal recursive solution that is executed in the form's constructor:

        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);
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号