views:

101

answers:

1

I have a MenuStrip that I have added to a form, and in one of the dropdown menus in it, I have a text box. When I hit enter on the textbox, I want a function to run, then the drop down menu to close. I know how to get the enter part done, but I have no idea how to close the MenuStrip dropdown menu. Does anybody know how to do this?

+1  A: 

Call the Owner's Hide() method. For example:

    private void toolStripTextBox1_KeyDown(object sender, KeyEventArgs e) {
        if (e.KeyData == Keys.Enter) {
            e.SuppressKeyPress = true;
            toolStripTextBox1.Owner.Hide();
        }
    }
Hans Passant
What if it's a submenu of another menu? How do I go up the chain of submenus to get to the very root of the menu? I tried Owner.Owner but that's undefined and Owner.Parent results in an Exception of "Parent not set".
Nilbert
Just call the HideDropDown() method of the particular menu item you want to hide.
Hans Passant