473,563 Members | 2,797 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Upgrading from MainMenu to MenuStrip

Included below are four methods and a Friend that can be inserted directly
into a form that already contains Button1, Button2, and MenuStrip1. Button1
populates the MainMenu control, button2 populates the MenuStrip control. The
MainMenu is from legacy 2003 and works fine. I want to upgrade to the
MenuStrip but cannot find a way to duplicate legacy code. Shown below is my
best effort. I am having two problems.

#1: ToolStripMenuIt em appears not support the cascading of the MenuItems()
which successfully works for a MenuItem. If there is not a fix, this means
significant recoding.

#2: When I click the last item in the menu hierarchy, I want to read back
through the hierarchy of the clicked Menu entry but can't seem to get past
the parent of the clicked item. This code crashes when I attempt to get the
grandparent.

Any Help will be appreciated. There does not seem to be much on the
Internet or at Microsoft covering the MenuStrip control and the
GetCurrentParen t() method or parent property.

Friend WithEvents MainMenu1 As System.Windows. Forms.MainMenu

Private Sub ButtonMnu_Click (ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button1.Click
Me.MainMenu1 = New System.Windows. Forms.MainMenu
Me.Menu = Me.MainMenu1
Dim omnuAdd As MenuItem = New MenuItem("Menu Bar Level")
MainMenu1.MenuI tems.Add(omnuAd d)
omnuAdd = New MenuItem("First Sub")
MainMenu1.MenuI tems(0).MenuIte ms.Add(omnuAdd)
omnuAdd = New MenuItem("Secon d Sub")
MainMenu1.MenuI tems(0).MenuIte ms(0).MenuItems .Add(omnuAdd)
omnuAdd = New MenuItem("Third Sub")
AddHandler omnuAdd.Click, AddressOf Me.mnuClick
MainMenu1.MenuI tems(0).MenuIte ms(0).MenuItems (0).MenuItems.A dd(omnuAdd)
End Sub

Private Sub mnuClick(ByVal sender As System.Object, ByVal e As
System.EventArg s)
Dim oMnu As MenuItem = CType(sender, MenuItem)
Dim oMnuParent As MenuItem = oMnu.Parent
oMnuParent.Menu Items.Add("Adde d to Parent")
oMnuParent = oMnuParent.Pare nt
oMnuParent.Menu Items.Add("Adde d to GrandParent")
End Sub

Private Sub ButtonStrip_Cli ck(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button2.Click
Dim oStripParent As ToolStripMenuIt em

Dim oStripAdd As New ToolStripMenuIt em("Menu Strip Level")
Me.MenuStrip1.I tems.Add(oStrip Add)

oStripParent = Me.MenuStrip1.I tems(Me.MenuStr ip1.Items.Count - 1)
oStripAdd = New ToolStripMenuIt em("First Sub")
oStripParent.Dr opDownItems.Add (oStripAdd)

oStripParent = oStripParent.Dr opDownItems(oSt ripParent.DropD ownItems.Count
- 1)
oStripAdd = (New ToolStripMenuIt em("Second Sub"))
oStripParent.Dr opDownItems.Add (oStripAdd)

oStripParent = oStripParent.Dr opDownItems(oSt ripParent.DropD ownItems.Count
- 1)
oStripAdd = (New ToolStripMenuIt em("Third Sub"))
AddHandler oStripAdd.Click , AddressOf Me.stripClick
oStripParent.Dr opDownItems.Add (oStripAdd)

End Sub

Private Sub stripClick(ByVa l sender As System.Object, ByVal e As
System.EventArg s)
Dim oStrip As ToolStripMenuIt em = CType(sender, ToolStripItem)
Dim oStripParent As ToolStrip = oStrip.GetCurre ntParent
oStripParent.It ems.Add("Added to Parent")
Dim oStripParent1 As ToolStrip = oStripParent.Pa rent
Dim oStripAdd As New ToolStripMenuIt em("Added to GrandParent")
Try
oStripParent1.I tems.Add(oStrip Add)
Catch ex As Exception
MsgBox("You crash here")
End Try
End Sub

Thank you
Sep 20 '06 #1
0 2957

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
2362
by: academic | last post by:
Using ToolStripManager.Merge(ToolStrip,ToolStrip) I've been able to merge a MenuStrip into a MenuStrip but never a ContextMenuStrip into a MenuStrip. From the docs it seems to me I should be able to.
2
2150
by: polocar | last post by:
Hi, I'm writing a program using Visual C# 2005 Professional Edition, and I was trying to assign multiple MainMenu objects (one by one, of course) to the same Form (let's suppose 2 MainMenu objects). It is possible (and it's my case) that these 2 MainMenu objects use some different MenuItem objects and some identical MenuItem objects. For...
0
1265
by: John J. Hughes II | last post by:
Asked this before and did not get an answer, will try again! I have an existing MDI application with dozens of child windows. Is there a simple way of changing the MainMenu to a MenuStrip along with the MenuItems? I tried changing the MainMenu type and link to the form which fixed the menu part but then all the MenuItems were lost and...
4
1770
by: cj | last post by:
I don't see the mainmenu item in the toolbox of 2005. I guess I haven't created a project in 2005 using it yet. I know I upgraded some from 2003 to 2005 and they show the control mainmenu on the form1.vb design page. What do I use? Menustrip?
1
1319
by: Benson | last post by:
I have a MainMenu (MenuStrip) which will be loaded (dynamic by codes) after the program Login form. The first time run is ok. But when I close the MainMenu and go back to Login form, and then go to MainMenu again, the menu items didn't clear by MainMenu.Items.Clear(). That is: 1. Login -MainMenu.items.clear() -MainMenu (dynamic add menu items...
2
4318
by: Fir5tSight | last post by:
Hi, I'm experimenting sample code created in Visual Studio 2002 (or 2003) in my Visual Studio 2005. However, I can't find the following in VS 2005: - MainMenu control in Toolbox; - MergeOrder property for a menu; - MdiList property for a menu.
3
2199
by: =?Utf-8?B?Sm9l?= | last post by:
Can anyone tell me if this is a confimed bug and if there is a workaround: - Create an form set as an mdi container - Add a Menustrip to mdi container and set form's MainMenuStrip property to newly created menu - Create mdi child form and set it's window state to Maximized When you run the project and open the child form, the menus are...
0
5032
by: kyungdongkim | last post by:
Hi, I have a dynamically generated MenuStrip following this example: http://www.codeproject.com/useritems/Dynamic_MenuStrip.asp Basically the menu strip allows users to save and load reports. The Load menu is to list all the saved reports. I need to refresh the Load menu after a new report is saved. Any help is much appreciated! ...
9
1829
by: Academia | last post by:
ContextMenu has a Popup event but MainMenu does not. I need Popup with MainMenu. Do you know anyway to simulate it? Thanks in advance
0
7665
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7583
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7888
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8106
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7642
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
3643
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3626
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2082
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1200
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.