Search code examples
c#.netwinformstoolstripmenustrip

ToolStripMenuItem show sub menu on Mouse hover in Windows Forms


I am having a windows form menu strip control. And having ToolStripMenu Item with text of "Click Me". Now i want to display its sub menu toolstrip items on Mouse Hover Event of the "Click Me" ToolStrip. Can any one suggest how its can be done.

enter image description here

Here on mousehover event i want to display its sub menu item like this

enter image description here


Solution

  • You can handle MouseHover event of the items and then using ShowDropDown method, open the dropdown. This way, menus will open on hover rather than click.

    For example:

    private void Form1_Load(object sender, EventArgs e)
    {
        this.menuStrip1.Items.OfType<ToolStripMenuItem>().ToList().ForEach(x =>
        {
            x.MouseHover += (obj, arg) => ((ToolStripDropDownItem)obj).ShowDropDown();
        });
    }