![]() ![]() If TypeOf (Current) Is ToolStripMenuItem Thenįor Each menu As ToolStripItem In DirectCast(Current, ToolStripMenuItem). Public Sub GetMenues(ByVal Current As ToolStripItem, ByRef menues As List(Of ToolStripItem)) Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Clickįor Each t As ToolStripItem In MenuStrip1.Items For that matter, can you show the code that you are using to loop through the COntrols collection? Is it also recursive - every control has it's own Controls collection? Be aware though that many controls can have the same ContextMenuStrip so you will need to have an ability buit in to determine when you have encountered it before (if you are trying to create a unique collection).Ĭould you explain a little better what you are going to do once you find all these items? And what are all the types of things that you are trying to find? There are likely other components that can be attached to a form that do not exist in the controls collection. This property will provide you the object that you can then drill down through. Each control in the collection(s) has a ContextMenuStrip property. The dynamic solution for the ContextMenuStrip would be the same as that of the MenuStrip. but some components are not a part of the form's controls collection. If I understand you correctly you are trying to loop through all of the form's controls to get. NET knows how to magically drop one of these menu items down, the. A menu item can optionally have subitems. The nature of a ToolStripItem is such that it can represent a toolbar button, or a menu item. All controls ultimately belong to the Form through n levels of container controls, but one ContextMenuStrip can be associated with a particular TextBox, and another with a group of ListBoxes, without being "in" the Form itself.Īll of that said, this component happens to be composed of controls, so once you get a reference to the component, you can iterate through its controls as described by Dig-Boy.Ī ContextMenuStrip should work the very same as a MenuStrip in that example. The MenuStrip itself boils down to being a specialized collection of ToolStripItem objects. Rather, it is accessed through a property of other controls, and the group of controls with which it is associated may or may not include the Form itself. A ContextMenuStrip is not tied to a specific location and it cannot be placed in a GroupBox, on a Panel, or in Table- or Flow- LayoutControls. ![]() When you drag it out of the ToolBox, it doesn't go onto the form, it sits down at the bottom of the designer along with ToolTips, data components, and the like - things that may or may not have a UI element, but which do not have a parent-control relationship with the form. Well, consider the functionality of the ContextMenuStrip. I wonder why MS made this a component and the MenuStrip a control.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |