Вопрос

I want to add menu to visual studio in AddIn. I found how to create submenu item in Expose an Add-In on the Tools Menu (Visual C#), but I want to create primary menu (like 'File', 'Edit', 'View' etc.) How can I do that using c#?

Это было полезно?

Решение

I think You can use this:

Microsoft.VisualStudio.CommandBars.CommandBar menuBarCommandBar = 
    ((Microsoft.VisualStudio.CommandBars.CommandBars)_applicationObject.CommandBars)["MenuBar"];

CommandBarPopup myNewPopUpControl = 
    menuBarCommandBar.Controls.Add(MsoControlType.msoControlPopup) as CommandBarPopup;

myNewPopUpControl.Caption = "MyMenu";
myNewPopUpControl.Visible = true;

First line is from the OnConnection of the Add-In template. As I experienced each element of Controls collection has a zero Id, so the arrangment might be problematic. Also you can create Buttons and PopUps with Automation (Exception will be thrown otherwise)

http://msdn.microsoft.com/en-us/library/microsoft.visualstudio.commandbars.commandbarcontrols.add.aspx http://msdn.microsoft.com/en-us/library/office/aa190793(v=office.10).aspx

Update: Your question seems to be a duplicate [a question] Adding a Menu to the Visual Studio Menu Bar within an Add-In [a]

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top