Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Closing a MenuStrip programmatically

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.

like image 350
Nilbert Avatar asked Dec 10 '22 15:12

Nilbert


1 Answers

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();
        }
    }
like image 131
Hans Passant Avatar answered Dec 29 '22 01:12

Hans Passant