12/25/2023 0 Comments Drop down menustrip![]() When the dropdown closes, I remove it from the menu item. When a receive a right-click event, I add a dropdown menu containing the actions I wish to be able to provide and show the dropdown. I have added a MouseUp event handler for all the items in the dropdown of a ToolStripDropDownButton. ![]() These are not submenus/dropdowns - they are true context menus.įor the time being, I have implemented a workaround that is not optimal, but will do in a pinch. Open Start/Programs, and a right-click on any of the menu items with "Programs" will bring up a context menu that includes "Delete", "Rename" and "Sort by Name". Right click on "Start/Microsoft Update" and you get a context menu that include "Open", "Run as." and "Properties". It has menu items (which have context menus), and some of those menu items have dropdowns (like Programs), whose items also have a context menu. What I want is something akin to the Start Menu in Windows XP. You can attach a ContextMenuStrip to a ToolStrip and give the "top-level" menus of that strip a context menu, but it appears to be impossible to do that to the dropdowns of a menu item (ToolStripDropDownButton or ToolStripMenuItem), mostly due to the fact that these "controls" are not derived from . And the single tool strip "control" that is derived from Control (ToolStripDropDown) deprecates the ContextMenuStrip property. I understand how to add sub-menus/dropdowns to existing menu items, what I was looking for was something different - a context menu for all the menu items within a drop down (or one that is specific to a menu item). ToolStripMenuItem fruitMenuItem = new ToolStripMenuItem("Fruit") įruitMenuItem.DropDownItemClicked += new ToolStripItemClickedEventHandler(myDropDownItemClicked) VeggiesMenuItem.DropDownItemClicked += new ToolStripItemClickedEventHandler(myDropDownItemClicked) ĬontextMenuStrip cms = new ContextMenuStrip() ToolStripMenuItem veggiesMenuItem = new ToolStripMenuItem("Veggies") ![]() The following sample shows these concepts. And you don't have to fish into the collection either, we just hand you back the item that was clicked on. This allows you a handy way to not have to sync each item in a ToolStrip DropDown's click event. Another handy feature of ToolStripDropDownItem is the DropDownItemClicked event. You can populate a dropdown via two different methods – either by hydrating the DropDownItems collection or assigning a created ContextMenuStrip to the ToolStripDropDownItem's DropDown property. Reopening the original menu is a mess.ĭoes anyone have an idea as to how to perform this (seemingly simple) task I've also tried overriding the MouseUp event on individual menu items, handling the right-click and just bringing up the context menu manually, but this results in original menu closing - which isn't very helpful to a user who wants to double-check that he/she is removing the correct menu item. I attempted to add a ContextMenuStrip to the parent ToolStrip, but it only affects the tool strip and its top-level menu items - right-clicking on submenus does not invoke the context menu. ![]() Unfortunately, ToolStripDropDownButton is not derived from, so it does not have a ContextMenuStrip property. If you go to Start/Programs, you can right-click on any menu item and get a context menu to open, delete, or rename the selected menu item. You can see similar behavior in the Windows Start Menu. To do this, I would like to be able to associate a ContextMenuStrip to some of these menus, which would have a "Delete" or "Remove", that, when selected, would remove the menu item. I'd like to offer a simple way for a user to remove a menu item from a menu. Several of these menus are dynamic - the items are added and removed programmatically, depending on actions the user has performed elsewhere (like the MRU files listing at the bottom of a File menu). I have a ToolStrip that has various drop down menus (ToolStripDropDownButtons). Posted: Windows Forms General, How to add a ContextMenuStrip to a ToolStripDropDownButton Index ‹ Windows Forms ‹ Windows Forms General How to add a ContextMenuStrip to a ToolStripDropDownButton
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |