문제

I have a ContextMenu like in this picture. Now i want to add where it says ".rtf" more MenuItems at runtime. I cant seem to make it...

Dim myContextMenu As ContextMenuStrip = Form1.mnuOptions
Dim myMenuItem As ToolStripMenuItem = myContextMenu.Items("SendTo")
Dim mySubMenuItem As New ToolStripMenuItem = myMenuItem.DropDownItems("File").SUBITEMS

This is how i imagine doing it, but it does not work of course because there is no ".subitems". What does it take to accomplish such an easy job?

And how can I set AddHandlers for each SubItem to a procedure?

도움이 되었습니까?

해결책

Assuming that 'File' is the name of the menu item with that text, you can access it directly by it's name, and add the dropdown item to its collection:

File.DropDownItems.Add("Pdf")

One of the Add overloads allows you to indicate which event handler the click will fire.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top