关于如何将无模式消息框显示为工具提示的想法 [英] Ideas on how to display a modeless message box as a tooltip

查看:24
本文介绍了关于如何将无模式消息框显示为工具提示的想法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每当用户将鼠标悬停在菜单项上时,我都需要显示一个无模式的消息框.我不能使用 messagebox.show(...) 因为它是一个模态.所以我所做的是创建一个单独的窗口表单并使用菜单项上的悬停事件显示该表单.我有两个问题:

I need to display a modeless message box whenever a user hovers over a menu item. I can't use messagebox.show(...) because it is a modal. So what I did was create a seperate windows form and display the form using the hover event on the menu item. I have 2 problems:

1) 当窗体显示时,菜单失去可见性.
2) Windows 窗体不像工具提示那样出现在菜单项旁边.

1) When the windows form displays the menu loses its visibility.
2) The windows form does not appear next to the menu item like how a tooltip would.

关于如何自定义组件的工具提示以使其看起来和行为类似于 Windows 窗体的任何想法?

Any ideas on how I could custmize a component's tooltip that will make it look and act like a windows form?

推荐答案

回答你的第二个问题:

如果您将 form.StartPosition 属性设置为 FormStartPosition.Manual,那么您可以将表单定位在光标处(例如):

If you set the form.StartPosition property to FormStartPosition.Manual then you can position the form at the cursor (for example):

form.StartPosition = FormStartPosition.Manual;
form.Location = new Point(Cursor.Position.X - 1, Cursor.Position.Y - 1);

这也可能有助于解决您的第一个问题.

This might help with your first problem too.

如果您希望表单表现得像工具提示,那么如果您添加以下事件处理程序代码,它可能会满足您的需求:

If you want the form to behave like a tooltip then if you add the following event handler code it might give you want you want:

    private void Form_MouseLeave(object sender, EventArgs e)
    {
        // Only close if cursor actually outside the popup and not over a label
        if (Cursor.Position.X < Location.X || Cursor.Position.Y < Location.Y ||
            Cursor.Position.X > Location.X + Width - 1 || Cursor.Position.Y > Location.Y + Height - 1)
        {
            Close();
        }
    }

这里解释了-1在设置表单位置时的作用.它确保光标在第一次显示时实际上位于表单上.

This explains the -1 in setting the form position. It ensures that the cursor is actually on the form when it first displays.

这篇关于关于如何将无模式消息框显示为工具提示的想法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆