|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
control collectionmenustripitems from the form? I usually would have done this by using the forms controlcollection. There I can find the menustrip control, but I would have expected to find the menustripitems as children from the menustrip. However my menustrip.controls.count = 0, although when running the form the menu work properly. Also trying to add the menu to a panel and the panel to the form does not change the behaviour; What´s wrong with that approach?? (Have read a number of articles of a recursive routine to run through the containers of the form, but the actual problem is that my menustrip items are not in the menustrip nor is the menustrip considered as a container which could contain menustripitems) Any comments are welcome. Thanks. Yes there is. I'll just copy the code I use to change the text of every menu
item in my app. This will give you enough of an idea of how to do your thing. Looping through all controls: ---------------------------- Private Sub LoopThroughControls(ByVal xControl As Control) Dim FormControls As Integer Dim Cntr As Integer = 0 Dim FormName As String = "" FormName = Me.Name If xControl.Controls.Count = 0 Then Exit Sub FormControls = xControl.Controls.Count For Cntr = 0 To FormControls - 1 If TypeOf xControl.Controls.Item(Cntr) Is System.Windows.Forms.MenuStrip Then GetMenuTexts(xControl.Controls.Item(Cntr)) ElseIf TypeOf xControl.Controls.Item(Cntr) Is System.Windows.Forms.ToolStrip Then GetToolbarTexts(xControl.Controls.Item(Cntr)) Else GetLabelForControlText(FormName, xControl.Controls.Item(Cntr)) LoopThroughControls(xControl.Controls.Item(Cntr)) End If Next End Sub Looping through all menus: --------------------------- Friend Sub GetMenuTexts(ByVal MyMenu As System.Windows.Forms.MenuStrip) Dim Cntr, MenuCount As Integer Dim LabelText As String MenuCount = MyMenu.Items.Count For Cntr = 0 To MenuCount - 1 LabelText = TextHandler.GetText(MyMenu.Name, MyMenu.Items(Cntr).Name) If LabelText <> "" Then MyMenu.Items(Cntr).Text = LabelText GetMenuItemTexts(MyMenu.Name, MyMenu.Items(Cntr)) End If Next End Sub Looping through every item of a menu: -------------------------------------- Friend Sub GetMenuItemTexts(ByVal MenuName As String, ByVal MyItem As System.Windows.Forms.ToolStripMenuItem) Dim Cntr, ItemCount As Integer Dim LabelText As String ItemCount = MyItem.DropDownItems.Count For Cntr = 0 To ItemCount - 1 LabelText = TextHandler.GetText(MenuName, MyItem.DropDownItems(Cntr).Name) If LabelText <> "" Then MyItem.DropDownItems(Cntr).Text = LabelText GetMenuItemTexts(MenuName, MyItem.DropDownItems(Cntr)) End If Next End Sub Show quoteHide quote "ctk_at" <ct***@discussions.microsoft.com> wrote in message news:808EFB90-6758-438C-A07A-09359422CA5A@microsoft.com... >I placed a menustrip on a form; is there any way to read the individual > menustripitems from the form? > I usually would have done this by using the forms controlcollection. There > I > can find the menustrip control, but I would have expected to find the > menustripitems as children from the menustrip. However my > menustrip.controls.count = 0, although when running the form the menu work > properly. > Also trying to add the menu to a panel and the panel to the form does not > change the behaviour; > What´s wrong with that approach?? > > (Have read a number of articles of a recursive routine to run through the > containers of the form, but the actual problem is that my menustrip items > are > not in the menustrip nor is the menustrip considered as a container which > could contain menustripitems) > > Any comments are welcome. > > Thanks. Yeah, that´s it thanks a lot,
Chris Show quoteHide quote "Martin" wrote: > Yes there is. I'll just copy the code I use to change the text of every menu > item in my app. This will give you enough of an idea of how to do your > thing. > > Looping through all controls: > ---------------------------- > > Private Sub LoopThroughControls(ByVal xControl As Control) > Dim FormControls As Integer > Dim Cntr As Integer = 0 > Dim FormName As String = "" > FormName = Me.Name > If xControl.Controls.Count = 0 Then Exit Sub > FormControls = xControl.Controls.Count > For Cntr = 0 To FormControls - 1 > If TypeOf xControl.Controls.Item(Cntr) Is > System.Windows.Forms.MenuStrip Then > GetMenuTexts(xControl.Controls.Item(Cntr)) > ElseIf TypeOf xControl.Controls.Item(Cntr) Is > System.Windows.Forms.ToolStrip Then > GetToolbarTexts(xControl.Controls.Item(Cntr)) > Else > GetLabelForControlText(FormName, xControl.Controls.Item(Cntr)) > LoopThroughControls(xControl.Controls.Item(Cntr)) > End If > Next > End Sub > > Looping through all menus: > --------------------------- > > Friend Sub GetMenuTexts(ByVal MyMenu As System.Windows.Forms.MenuStrip) > Dim Cntr, MenuCount As Integer > Dim LabelText As String > MenuCount = MyMenu.Items.Count > For Cntr = 0 To MenuCount - 1 > LabelText = TextHandler.GetText(MyMenu.Name, > MyMenu.Items(Cntr).Name) > If LabelText <> "" Then > MyMenu.Items(Cntr).Text = LabelText > GetMenuItemTexts(MyMenu.Name, MyMenu.Items(Cntr)) > End If > Next > End Sub > > Looping through every item of a menu: > -------------------------------------- > > Friend Sub GetMenuItemTexts(ByVal MenuName As String, ByVal MyItem As > System.Windows.Forms.ToolStripMenuItem) > Dim Cntr, ItemCount As Integer > Dim LabelText As String > ItemCount = MyItem.DropDownItems.Count > For Cntr = 0 To ItemCount - 1 > LabelText = TextHandler.GetText(MenuName, > MyItem.DropDownItems(Cntr).Name) > If LabelText <> "" Then > MyItem.DropDownItems(Cntr).Text = LabelText > GetMenuItemTexts(MenuName, MyItem.DropDownItems(Cntr)) > End If > Next > End Sub > > > > > "ctk_at" <ct***@discussions.microsoft.com> wrote in message > news:808EFB90-6758-438C-A07A-09359422CA5A@microsoft.com... > >I placed a menustrip on a form; is there any way to read the individual > > menustripitems from the form? > > I usually would have done this by using the forms controlcollection. There > > I > > can find the menustrip control, but I would have expected to find the > > menustripitems as children from the menustrip. However my > > menustrip.controls.count = 0, although when running the form the menu work > > properly. > > Also trying to add the menu to a panel and the panel to the form does not > > change the behaviour; > > What´s wrong with that approach?? > > > > (Have read a number of articles of a recursive routine to run through the > > containers of the form, but the actual problem is that my menustrip items > > are > > not in the menustrip nor is the menustrip considered as a container which > > could contain menustripitems) > > > > Any comments are welcome. > > > > Thanks. > > >
VB.Net 2005 Treeview example required
WebBrowser Handles keyword. FileStream is adding extra characters Getting icon from form in dynamically loaded DLL Optimizing Repeated PictureBox.Paints padding text field with blank in MS Access vs OLEDB Jet 4.0 Parsing XML strings Browsers Block Step Into Debugging for a function |
|||||||||||||||||||||||