Frage

I am using a NotifyIcon control, associated with a ContextMenuStrip to display a multi-level menu. I need to load the new branch of the submenu, when the user's mouse hovers on selected item.

Unfortunately, ContextMenuStrip does not have event for capturing MouseHover events, so I would like to use ToolStripMenuItem controls, instead of standard ToolStripItem controls.

ToolStripMenuItem has an event called MouseHover, but I need one event handler for all items in the menu. I don't have an idea how I can do that. Below is part of my code, which I use to add an event handler to a single ToolStripMenuItem.

ToolStripMenuItem mi = new ToolStripMenuItem();
mi.Text = "Hello";
Menu.Items.Add(mi);

mi.MouseHover += new EventHandler(mi_MouseHover);
War es hilfreich?

Lösung

You can write a specific Event Handler to use it for all Tool Strip Menu Items

    private void ToolStripHover(object sender, EventArgs e)
    {
        //Do Something
    }


 mi.MouseHover += new EventHandler(ToolStripHover);

Or you can copy ToolStripHover and paste it to each Menu Item's MouseHover event if you are using Visual Studio.

Andere Tipps

You can try MouseEnter event for this..

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top