Ideas on how to display a modeless message box as a tooltip

c#, tooltip, winforms

Solution

To answer your second problem:

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();
        }
    }

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

Problem

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) 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. Any ideas on how I could custmize a component's tooltip that will make it look and act like a windows form?

Original source