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
2010-05-24 14:25:06
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
2010-05-25 16:21:57
Just call the HideDropDown() method of the particular menu item you want to hide.
Hans Passant
2010-05-25 16:54:14