473,387 Members | 1,440 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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: ToolStripMenuItem 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
GetCurrentParent() 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.EventArgs) Handles Button1.Click
Me.MainMenu1 = New System.Windows.Forms.MainMenu
Me.Menu = Me.MainMenu1
Dim omnuAdd As MenuItem = New MenuItem("Menu Bar Level")
MainMenu1.MenuItems.Add(omnuAdd)
omnuAdd = New MenuItem("First Sub")
MainMenu1.MenuItems(0).MenuItems.Add(omnuAdd)
omnuAdd = New MenuItem("Second Sub")
MainMenu1.MenuItems(0).MenuItems(0).MenuItems.Add( omnuAdd)
omnuAdd = New MenuItem("Third Sub")
AddHandler omnuAdd.Click, AddressOf Me.mnuClick
MainMenu1.MenuItems(0).MenuItems(0).MenuItems(0).M enuItems.Add(omnuAdd)
End Sub

Private Sub mnuClick(ByVal sender As System.Object, ByVal e As
System.EventArgs)
Dim oMnu As MenuItem = CType(sender, MenuItem)
Dim oMnuParent As MenuItem = oMnu.Parent
oMnuParent.MenuItems.Add("Added to Parent")
oMnuParent = oMnuParent.Parent
oMnuParent.MenuItems.Add("Added to GrandParent")
End Sub

Private Sub ButtonStrip_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
Dim oStripParent As ToolStripMenuItem

Dim oStripAdd As New ToolStripMenuItem("Menu Strip Level")
Me.MenuStrip1.Items.Add(oStripAdd)

oStripParent = Me.MenuStrip1.Items(Me.MenuStrip1.Items.Count - 1)
oStripAdd = New ToolStripMenuItem("First Sub")
oStripParent.DropDownItems.Add(oStripAdd)

oStripParent = oStripParent.DropDownItems(oStripParent.DropDownIt ems.Count
- 1)
oStripAdd = (New ToolStripMenuItem("Second Sub"))
oStripParent.DropDownItems.Add(oStripAdd)

oStripParent = oStripParent.DropDownItems(oStripParent.DropDownIt ems.Count
- 1)
oStripAdd = (New ToolStripMenuItem("Third Sub"))
AddHandler oStripAdd.Click, AddressOf Me.stripClick
oStripParent.DropDownItems.Add(oStripAdd)

End Sub

Private Sub stripClick(ByVal sender As System.Object, ByVal e As
System.EventArgs)
Dim oStrip As ToolStripMenuItem = CType(sender, ToolStripItem)
Dim oStripParent As ToolStrip = oStrip.GetCurrentParent
oStripParent.Items.Add("Added to Parent")
Dim oStripParent1 As ToolStrip = oStripParent.Parent
Dim oStripAdd As New ToolStripMenuItem("Added to GrandParent")
Try
oStripParent1.Items.Add(oStripAdd)
Catch ex As Exception
MsgBox("You crash here")
End Try
End Sub

Thank you
Sep 20 '06 #1
0 2947

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

Similar topics

0
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...
2
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...
0
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...
4
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...
1
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...
2
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; -...
3
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...
0
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. ...
9
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
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...

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.