4

I work on a c# winform project that the main toolstripmenu have not to be hide after user clicks on its item, how can I do that?

enter image description here

8
  • 2
    Could you make an picture or something? Because as far as I understand it, you can't click on a item from a toolstripmenu that isn't 'opened'. So basically I don't understand.
    – Kilazur
    Feb 4, 2015 at 8:27
  • @Kilazur I Opened toolstripmenu and click on its items, when I click on a item the toolstriped menu closed automatically. I don't want it hides after clicking.
    – ArMaN
    Feb 4, 2015 at 8:31
  • Then when you want it to close? and how? Feb 4, 2015 at 8:48
  • @SriramSakthivel it close when I click on a exit button for example.
    – ArMaN
    Feb 4, 2015 at 8:52
  • 1
    Does that ToolStripMenuItem is added to ToolStrip or ContextMenuStrip? If latter it is easy to do what you're asking. Feb 4, 2015 at 9:07

2 Answers 2

8

Set the AutoClose property of the parent menu item to prevent the menu strip from closing.

To demonstrate:

ToolStripMenuItem file = new ToolStripMenuItem("File");
file.DropDown.AutoClose = false;
file.DropDownItems.Add("New");
file.DropDownItems.Add("Open");
file.DropDownItems.Add("Exit");

MenuStrip ms = new MenuStrip();
ms.Items.Add(file);

this.Controls.Add(ms);

Now the responsibility is on you to close the menu yourself:

file.DropDown.Close();
7

I found better answer on MSDN forum. Dropdown doesn't close on click, but closes in other cases:

DropDown.Closing += new ToolStripDropDownClosingEventHandler(DropDown_Closing);
...
private void DropDown_Closing(object sender,  ToolStripDropDownClosingEventArgs e)
{
    if (e.CloseReason == ToolStripDropDownCloseReason.ItemClicked)
    {
        e.Cancel = true;
    }
}
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.