It's not a bug. It's a feature.
In fact the drop down menu will be hidden automatically after the code executing in the DropDownItemClicked
event handler. However you use some kind of MessageBox
or ShowDialog
which will block the current execution and hang the drop down menu there.
There are at least 2 solutions for you to solve this, one is hide the menu yourself before showing the Dialog (this seems to be adopted by you). The another solution is using BeginInvoke
to show your dialog, that async
call won't block the current execution and the drop down menu will be hidden expectedly:
private void fileToolStripMenuItem_DropDownItemClicked(object sender, ToolStripItemClickedEventArgs e){
if (e.ClickedItem.Name == "openToolStripMenuItem")
{
BeginInvoke((Action)(()=>{
if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
MessageBox.Show(openFileDialog1.FileName);
}));
}
}
NOTE: to hide the drop down menu
manually in the DropDownItemClicked
event handler, you can use e.ClickedItem.Owner.Hide()
instead of FileToolStripMenuItem.HideDropDown()
.