C# MenuStrip control realizes the automatic pop-up function when the mouse slides over

Time:2021-10-24

MenuStrip control is a menu bar control that can load the menu bar, which is useful in many systems. This article introduces the common methods of some properties of this control.

On the page formmain_ Add the following registration events to load:


 for (int i = 0; i < this.toolStrip1.Items.Count; i++) {
                this.toolStrip1.Items[i].MouseHover += new EventHandler(toolStrip1_MouseHover);
            }

Add method:


private void toolStrip1_MouseHover(object sender, EventArgs e) {
            if (sender is ToolStripDropDownItem) {
                ToolStripDropDownItem item = sender as ToolStripDropDownItem;
                if (item.HasDropDownItems && !item.DropDown.Visible) {
                    item.ShowDropDown();
                }
            }

        }

Extension: let’s share a sample code: MenuStrip mouse automatically displays the menu


//---------------------------------------------------------------------------------
private void Form1_Load(object sender, EventArgs e)
{
    this.menuStrip1.Items[0].MouseHover += new EventHandler(Form1_MouseHover);
}

//---------------------------------------------------------------------------------
void Form1_MouseHover(object sender, EventArgs e)
{
    if (sender is ToolStripDropDownItem)
    {
        ToolStripDropDownItem item = sender as ToolStripDropDownItem;
        if (item.HasDropDownItems && !item.DropDown.Visible)
        {
            item.ShowDropDown();
        }
    }
}

This is the end of this article about MenuStrip mouse over automatic pop-up. For more relevant MenuStrip mouse over automatic pop-up content, please search the previous articles of developeppaer or continue to browse the relevant articles below. I hope you will support developeppaer in the future!

Recommended Today

OC basis

IOS development interview essential skills chart.png What are objects and what are the objects in OC? An object is an instance of a class; Is an instance created through a class, which is generally called an instance object; Common objects in OC include instance objects, class objects, and metaclass objects; What is a class? What […]