protected CommandBarButton AddButton(CommandBarPopup parentMenu, string caption, bool beginGroup, CommandBarButtonClickEvent buttonClickHandler, Bitmap image) { var button = AddButton(parentMenu, caption, beginGroup, buttonClickHandler); SetButtonImage(button, image); return button; }
protected CommandBarButton AddButton(CommandBarPopup parentMenu, string caption, bool beginGroup, CommandBarButtonClickEvent buttonClickHandler, int faceId) { var button = AddButton(parentMenu, caption, beginGroup, buttonClickHandler); button.FaceId = faceId; return button; }
private Office.CommandBarButton CreateCommandBarButton( Office.CommandBar commandBar, string captionText, string tagText, string tipText, Office.MsoButtonStyle buttonStyle, System.Drawing.Bitmap picture, bool beginGroup, bool isVisible, object objBefore, Office._CommandBarButtonEvents_ClickEventHandler handler) { // Determine if button exists Office.CommandBarButton aButton = (Office.CommandBarButton) commandBar.FindControl(buttonStyle, null, tagText, null, null); if (aButton == null) { // Add new button aButton = (Office.CommandBarButton) commandBar.Controls.Add(Office.MsoControlType.msoControlButton, 1, tagText, objBefore, true); aButton.Caption = captionText; aButton.Tag = tagText; if (buttonStyle != Office.MsoButtonStyle.msoButtonCaption) { aButton.Picture = (IPictureDisp)AxHost2.GetIPictureDispFromPicture(picture); } aButton.Style = buttonStyle; aButton.TooltipText = tipText; aButton.BeginGroup = beginGroup; aButton.Click += handler; } aButton.Visible = isVisible; return(aButton); }
protected CommandBarButton AddButton(CommandBarPopup parentMenu, string caption, bool beginGroup, CommandBarButtonClickEvent buttonClickHandler) { var button = AddButton(parentMenu, caption); button.BeginGroup = beginGroup; button.Click += buttonClickHandler; return button; }
private MOC.CommandBarButton add_menu_item(MOC.CommandBarPopup cmdbarpopup, string tag, string caption, MOC._CommandBarButtonEvents_ClickEventHandler handler) { tag = tagprefixmenuitem + tag; var btn = cmdbarpopup.AddNewMenuItem(tag, caption, (MOC.CommandBarButton Ctrl2, ref bool CancelDefault2) => wrap_handler(handler, Ctrl2, ref CancelDefault2)); buttons.Add(btn); return(btn); }
private void ThisAddIn_Startup(object sender, System.EventArgs e) { _ReportSpam = ReportSpam; _ReportHam = ReportHam; _ReportSelected = ReportSelected; _SafeView = SafeView; _CopyToClipboard = CopyToClipboard; _Settings = Settings; Explorer _objExplorer = Globals.ThisAddIn.Application.ActiveExplorer(); //_cbSpamGrabber = _objExplorer.CommandBars.Add("SpamGrabber", Office.MsoBarPosition.msoBarTop, false, true); _cbSpamGrabber = _objExplorer.CommandBars["Standard"]; _cbbDefaultSpam = CreateCommandBarButton(_cbSpamGrabber, "Report Spam", "Report to Default Spam profile", "Report to Default Spam profile", Office.MsoButtonStyle.msoButtonIcon, Properties.Resources.spamgrab_red, true, true, _cbSpamGrabber.Controls.Count, _ReportSpam); _cbbDefaultHam = CreateCommandBarButton(_cbSpamGrabber, "Report Ham", "Report to Default Ham profile", "Report to Default Ham profile", Office.MsoButtonStyle.msoButtonIcon, Properties.Resources.spamgrab_green, false, GlobalSettings.ShowHamButton, _cbSpamGrabber.Controls.Count, _ReportHam); _cbcbProfile = AddComboBox(_cbSpamGrabber); _cbcbProfile.Visible = GlobalSettings.ShowSelectButton; _cbbReportSelected = CreateCommandBarButton(_cbSpamGrabber, "Report", "Report to Selected Profile", "Report to Selected Profile", Office.MsoButtonStyle.msoButtonCaption, null, false, GlobalSettings.ShowSelectButton, _cbSpamGrabber.Controls.Count, _ReportSelected); _cbbPreview = CreateCommandBarButton(_cbSpamGrabber, "Safe View", "Safe Preview", "Safe Preview", Office.MsoButtonStyle.msoButtonIcon, Properties.Resources.search4doc, true, GlobalSettings.ShowPreviewButton, _cbSpamGrabber.Controls.Count, _SafeView); _cbbCopyToClipboard = CreateCommandBarButton(_cbSpamGrabber, "Copy Source", "Copy Source to Clipboard", "Copy Source to Clipboard", Office.MsoButtonStyle.msoButtonIcon, Properties.Resources.spamgrab_copy, false, GlobalSettings.ShowCopyButton, _cbSpamGrabber.Controls.Count, _CopyToClipboard); _cbbOptions = CreateCommandBarButton(_cbSpamGrabber, "Options", "SpamGrabber Options", "SpamGrabber Options", Office.MsoButtonStyle.msoButtonIcon, Properties.Resources.spamgrab_settings, false, GlobalSettings.ShowSettingsButton, _cbSpamGrabber.Controls.Count, _Settings); Reporting.Application = Globals.ThisAddIn.Application; }
public void AddUnmapButtonMenuCommand() { Office._CommandBarButtonEvents_ClickEventHandler xButtonHandler = new Office._CommandBarButtonEvents_ClickEventHandler(unmapXMLClick); Office._CommandBarButtonEvents_ClickEventHandler cButtonHandler = new Office._CommandBarButtonEvents_ClickEventHandler(unmapHeaderClick); Office._CommandBarButtonEvents_ClickEventHandler lButtonHandler = new Office._CommandBarButtonEvents_ClickEventHandler(unmapListClick); //Uncomment and Loop to find correct command dropdown menu. /* Office.CommandBars commandBars; commandBars = (Office.CommandBars)Application.CommandBars; foreach (Office.CommandBar commandBar in commandBars) { string name = commandBar.Name; string iName = commandBar.Name; try { Office.CommandBarButton testButton = (Office.CommandBarButton)Application.CommandBars[commandBar.Name].Controls.Add(Office.MsoControlType.msoControlButton, missing, missing, missing, true); testButton.Caption = commandBar.Name; testButton.Visible = true; //Uncomment when you want to clear the junk you just added. Application.CommandBars[commandBar.Name].Reset(); } catch (Exception e) { } } */ ClearInListButton = (Office.CommandBarButton)Application.CommandBars["List Range Popup"].Controls.Add(Office.MsoControlType.msoControlButton, missing, missing, missing, true); ClearInListButton.Click += lButtonHandler; ClearInListButton.Caption = "Remove Mapping"; ClearInListButton.Visible = true; XMLUnmapButton = (Office.CommandBarButton)Application.CommandBars["XML Range Popup"].Controls.Add(Office.MsoControlType.msoControlButton, missing, missing, missing, true); XMLUnmapButton.Click += xButtonHandler; XMLUnmapButton.Caption = "Unmap Values"; XMLUnmapButton.Visible = true; CellUnmapButton = (Office.CommandBarButton)Application.CommandBars["Cell"].Controls.Add(Office.MsoControlType.msoControlButton, missing, missing, missing, true); CellUnmapButton.Click += cButtonHandler; CellUnmapButton.Caption = "Clear Cell"; CellUnmapButton.Visible = true; }
public Office.CommandBarButton AddOptionToContextMenu(String name, int beforePos , Office._CommandBarButtonEvents_ClickEventHandler handler) { Office.CommandBars commandbars = Globals.ThisAddIn.Application.CommandBars; Office.CommandBar ccb = commandbars["Cell"]; Office.CommandBarButton button = (Office.CommandBarButton)ccb.Controls.Add(Office.MsoControlType.msoControlButton, missing, missing, beforePos + 1, true); button.Style = Office.MsoButtonStyle.msoButtonCaption; button.Caption = name; button.Tag = name; button.Visible = true; button.Click += handler; return(button); }
static void Main(string[] args) { Office.CommandBarButton Button; Office.CommandBar CommandBar; object Missing = System.Reflection.Missing.Value; Office._CommandBarButtonEvents_ClickEventHandler ButtonHandler; Word.ApplicationClass MyWord = new Word.ApplicationClass(); MyWord.Visible = true; CommandBar = MyWord.CommandBars.Add("MyCommandBar", Missing, Missing, Missing); Button = (Office.CommandBarButton)CommandBar.Controls.Add(Office.MsoControlType.msoControlButton, Missing, Missing, Missing, Missing); Button.Caption = "MyButton"; Button.FaceId = 1845; ButtonHandler = new Office._CommandBarButtonEvents_ClickEventHandler(OnClick_Button); Button.Click += ButtonHandler; System.Windows.Forms.Application.Run(); }
public void AddUnmapButtonMenuCommand() { Office._CommandBarButtonEvents_ClickEventHandler xButtonHandler = new Office._CommandBarButtonEvents_ClickEventHandler(unmapXMLClick); Office._CommandBarButtonEvents_ClickEventHandler cButtonHandler = new Office._CommandBarButtonEvents_ClickEventHandler(unmapHeaderClick); XMLUnmapButton = (Office.CommandBarButton)Application.CommandBars["XML Range Popup"].Controls.Add(Office.MsoControlType.msoControlButton, missing, missing, missing, true); XMLUnmapButton.Click += xButtonHandler; XMLUnmapButton.Caption = "Unmap Values"; XMLUnmapButton.Visible = true; CellUnmapButton = (Office.CommandBarButton)Application.CommandBars["Cell"].Controls.Add(Office.MsoControlType.msoControlButton, missing, missing, missing, true); CellUnmapButton.Click += cButtonHandler; CellUnmapButton.Caption = "Clear Cell"; CellUnmapButton.Visible = true; }
private void wrap_handler(MOC._CommandBarButtonEvents_ClickEventHandler handler, MOC.CommandBarButton Ctrl, ref bool CancelDefault) { try { handler(Ctrl, ref CancelDefault); } catch (VA.AutomationException exc) { process_exception(exc, typeof(VA.AutomationException).Name); } catch (COMException exc) { process_exception(exc, typeof(COMException).Name); } catch (System.Exception exc) { process_exception(exc, typeof(System.Exception).Name); throw; } }
private CommandBarButton AddButton(CommandBarPopup parentMenu, string caption, bool beginGroup, CommandBarButtonClickEvent buttonClickHandler) { var button = parentMenu.Controls.Add(MsoControlType.msoControlButton, Temporary: true) as CommandBarButton; button.Caption = caption; button.BeginGroup = beginGroup; button.Click += buttonClickHandler; return(button); }
protected CommandBarButton AddButton(CommandBar commandBar, int before, string caption, bool beginGroup, CommandBarButtonClickEvent buttonClickHandler, string imageName) { var button = AddButton(commandBar, before, caption); button.BeginGroup = beginGroup; button.Click += buttonClickHandler; SetButtonImage(button, imageName); return(button); }
protected CommandBarButton AddButton(CommandBarPopup parentMenu, string caption, bool beginGroup, CommandBarButtonClickEvent buttonClickHandler) { var button = AddButton(parentMenu, caption); button.BeginGroup = beginGroup; button.Click += buttonClickHandler; return(button); }
protected CommandBarButton AddButton(CommandBarPopup parentMenu, string caption, bool beginGroup, CommandBarButtonClickEvent buttonClickHandler, Bitmap image) { var button = AddButton(parentMenu, caption, beginGroup, buttonClickHandler); SetButtonImage(button, image); return(button); }
protected CommandBarButton AddButton(CommandBarPopup parentMenu, string caption, bool beginGroup, CommandBarButtonClickEvent buttonClickHandler, int faceId) { var button = AddButton(parentMenu, caption, beginGroup, buttonClickHandler); button.FaceId = faceId; return(button); }