Reputation: 73
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.
Here on mousehover event i want to display its sub menu item like this
Upvotes: 1
Views: 5623
Reputation: 73
System.Windows.Forms.ToolStripMenuItem clickmeeToolStripMenuItem
this.clickmeeToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem()
this.clickmeeToolStripMenuItem.MouseHover += new System.EventHandler(this.clickmeeToolStripMenuItem_MouseHover);
//ADD THIS METHOD TO YOUR EVENT METHOD
clickmeeToolStripMenuItem.ShowDropDown();
Upvotes: 0
Reputation: 125197
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();
});
}
Upvotes: 3