How to get the text of sub menus in MenuStrip? Please help.

marksquall

Active member
Joined
Oct 17, 2009
Messages
28
Programming Experience
3-5
Dear members and administrators,

Hello, A greeting of peace.

It is been quite difficult to "translate" my VB6 codes to VB .NET, but I am always trying my best.

But now, I am having trouble in getting the string of sub menus in a MenuStrip, which is very easy in VB 6.0's Menu Editor.

Assume we have this Help Menu created in Menu Editor in VB 6.0:



The Help Menu has two sub menus: View Help and About respectively. When putting functionality on the two sub menus, I will put the code inside the Help's Click event:

VB.NET:
[COLOR="#0000FF"]Private Sub[/COLOR] menuHelpSub_Click(Index [COLOR="#0000FF"]As Integer[/COLOR])
     [COLOR="#0000FF"]Select Case[/COLOR] menuHelpSub(Index).Caption
           [COLOR="#0000FF"] Case[/COLOR] "View Help"
                Form1.Show  (1)
           [COLOR="#0000FF"]Case[/COLOR] "About"
               Form2.Show (2)
     [COLOR="#0000FF"]End Select[/COLOR]
[COLOR="#0000FF"]End Sub[/COLOR]


Now when I create the same thing using MenuStrip in VB .NET, oh my golly :sorrow:...I am stuck within the body of Help menu's Click Event:

VB.NET:
[COLOR="#0000FF"]Private Sub[/COLOR] HelpToolStripMenuItem_Click([COLOR="#0000FF"]ByVal[/COLOR] sender [COLOR="#0000FF"]As[/COLOR] System.[COLOR="#02BECF"]Object[/COLOR], [COLOR="#0000FF"]ByVal[/COLOR] e [COLOR="#0000FF"]As[/COLOR] System.[COLOR="#02BECF"]EventArgs[/COLOR]) [COLOR="#0000FF"]Handles[/COLOR]  HelpToolStripMenuItem.Click
     [COLOR="#008000"]'I am stuck here...
     'what will I put here, please help...[/COLOR]
[COLOR="#0000FF"]End Sub[/COLOR]

I hope someone could help me with this codes...

Thank you and more power.



Warm regards,

Mark Squall
 
You can simply forget that VB6 code altogether. For a start, you don't handle the Click event of the Help menu item because you don't want to do anything when the user clicks it. You only want to do something when the user clicks one of the sub menu items, so you need to handle the Click event of those. You handle the Click events for each menu item separately, just as you would for two separate Buttons. As such, you don;t care about any text so there's no need to even look for it. In one handler you open one form and in the other you open the other. What could be simpler? Despite appearances, VB.NET is a different language to VB6. Don't try to convert VB6 code. Just decide what functionality you need to use and look for best way to implement that functionality in VB.NET. How you would have done it in VB6 is irrelevant.
 
Thank you for the advice jmcilhinney , I just thought of having similar code in VB6, so that just one procedure can handle all sub-menu's click event. I did your advice and I will go for it.


Thank you jmcilhinney and more power. :D


Warm regards,

MarkSquall
 
Last edited:
Back
Top