public static CommandBarPopup add_SubMenu(this CommandBarPopup topMenu, string text = "New Menu Item", int before = 0) { if (topMenu.isNull()) { "[VS_Menus_ExtensionMethods][add_Menu_Popup] provided topMenu was null so can't create menu: {0}".error(text); return(null); } if (before == 0) { before = topMenu.Controls.Count + 1; // to put it at the end } var menuItem = (CommandBarPopup)topMenu.Controls.Add(MsoControlType.msoControlPopup, // type System.Type.Missing, // id System.Type.Missing, // parameter before, // before false); // temporary menuItem.Caption = text; menuItem.Enabled = true; return(menuItem); }
public static CommandBarPopup add_Menu_Button(this CommandBarPopup topMenu, string text = "New Button", Action onClick = null, int before = 0) { if (topMenu.isNull()) { "[VS_Menus_ExtensionMethods][add_Menu_Button] provided topMenu was null so can't create menu button: {0}".error(text); return(null); } if (before == 0) { before = topMenu.Controls.Count + 1; // to put it at the end } var button = (CommandBarButton)topMenu.Controls.Add(MsoControlType.msoControlButton, // type System.Type.Missing, // id System.Type.Missing, // parameter before, // before false); // temporary button.Click += (CommandBarButton sender, ref bool CancelDefault) => onClick.invoke(); button.Caption = text; button.Enabled = true; return(topMenu); }