From: JB on 5 Apr 2010 20:10 Hi All, I've always so far designed menus at design time and never had a problem. Today I want to create menus programmatically and add Sub Menus to a ContextMenuStrip. How can I programmatically reproduce what I do at design time by setting the DropDown property of a Menu Item to the Sub Menu I wat to attach to it? The DropDown property doesn't exist on a ToolStripItem and I've tried to play with the Owner property without any luck. Any help or pointer would be greatly appreciated. Thanks JB
From: Herfried K. Wagner [MVP] on 5 Apr 2010 20:28 "JB" <jb.brossard(a)gmail.com> schrieb: > I've always so far designed menus at design time and never had a > problem. > Today I want to create menus programmatically and add Sub Menus to a > ContextMenuStrip. > How can I programmatically reproduce what I do at design time by > setting the DropDown property of a Menu Item to the Sub Menu I wat to > attach to it? > > The DropDown property doesn't exist on a ToolStripItem and I've tried > to play with the Owner property without any luck. Just check the button on top of the solution explorer to show hidden files. Then navigate to the "<form name>.Designer.vb" file of a form on which you already added the toolstrip. It will contain the source code generated by the designer to set up the menu. This should give you an idea on how to create the menus. -- M S Herfried K. Wagner M V P <URL:http://dotnet.mvps.org/> V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
From: JB on 5 Apr 2010 21:15 On 5 Apr, 17:28, "Herfried K. Wagner [MVP]" <hirf-spam-me-h...(a)gmx.at> wrote: > "JB" <jb.bross...(a)gmail.com> schrieb: > > > I've always so far designed menus at design time and never had a > > problem. > > Today I want to create menus programmatically and add Sub Menus to a > > ContextMenuStrip. > > How can I programmatically reproduce what I do at design time by > > setting the DropDown property of a Menu Item to the Sub Menu I wat to > > attach to it? > > > The DropDown property doesn't exist on a ToolStripItem and I've tried > > to play with the Owner property without any luck. > > Just check the button on top of the solution explorer to show hidden files. > Then navigate to the "<form name>.Designer.vb" file of a form on which you > already added the toolstrip. It will contain the source code generated by > the designer to set up the menu. This should give you an idea on how to > create the menus. > > -- > M S Herfried K. Wagner > M V P <URL:http://dotnet.mvps.org/> > V B <URL:http://dotnet.mvps.org/dotnet/faqs/> Thanks very much for that tip Herfried. I found the trick. The designer uses a ToolStripMenuItem class and not a ToolStripItem as returned by the ToolStripItemCollection.Add function.
|
Pages: 1 Prev: HTML report in vb.net Next: Adding/copying Worksheet to Excel |