/// <summary> /// Implements the OnBeginShutdown method of the IDTExtensibility2 interface. /// Receives notification that the host application is being unloaded. /// </summary> /// <param term='custom'> /// Array of parameters that are host application specific. /// </param> /// <seealso class='IDTExtensibility2' /> public void OnBeginShutdown(ref System.Array custom) { try { // TODO: Figure out how to gracefully remove menu items at shutdown // so that they're gone if the add-in is uninstalled; if (logger != null) { logger.LogMessage("Starting primary shutdown routine"); } RemoveMenuItems(); menuBar = null; btnSync = null; btnSettings = null; btnAbout = null; syncMgr.StopTimer(); syncMgr = null; } catch (System.Exception ex) { ErrorHandler.PublishError(ex, logger); } }
protected void AddMenu(ref Office.CommandBarButton btn, Office.CommandBar bar, string strCaption, string strTooltip, Microsoft.Office.Core._CommandBarButtonEvents_ClickEventHandler handler) { btn = (Office.CommandBarButton)bar.Controls.Add(Office.MsoControlType.msoControlButton, missing, missing, missing, true); AddMenu(btn, strCaption, strTooltip, handler); }
private void AddMenuBar() { try { menuBar = this.Application.ActiveExplorer().CommandBars.ActiveMenuBar; newMenuBar = (Office.CommandBarPopup)menuBar.Controls.Add( Office.MsoControlType.msoControlPopup, missing, missing, missing, false); if (newMenuBar != null) { newMenuBar.Caption = "AutoTask"; newMenuBar.Tag = menuTag; buttonOne = (Office.CommandBarButton)newMenuBar.Controls.Add(Office.MsoControlType.msoControlButton, Type.Missing, Type.Missing, 1, true); buttonOne.Style = Office.MsoButtonStyle.msoButtonIconAndCaption; buttonOne.Caption = "AutoTask"; buttonOne.FaceId = 65; buttonOne.Tag = "AutoTask"; buttonOne.Picture = getImage(); newMenuBar.Visible = true; } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
/// <summary> /// Add SyncBar if it is not there. /// When creating a command bar or a button, Outlook just has the meta data of the GUI updated. So even after the assembly of the addin /// is removed, the command bar along with the buttons are still there. /// http://www.add-in-express.com/docs/net-commandbar-tips.php#visibility-rules /// </summary> void AddSyncBar() { Outlook.Explorer explorer = Application.ActiveExplorer(); IEnumerable <Office.CommandBar> bars = explorer.CommandBars.OfType <Office.CommandBar>().Where(item => item.Name == syncBarName); syncBar = bars.FirstOrDefault(); if (syncBar == null) { syncBar = explorer.CommandBars.Add(syncBarName, Office.MsoBarPosition.msoBarTop, false, false); } #if DEBUG ClearButtons(); #endif syncButton = GetButton("Fonlow.SyncML.Sync", "Sync", "Display the sync center", OutlookSyncMLAddIn.Properties.Resources.sync16); syncButton.Click += new Microsoft.Office.Core._CommandBarButtonEvents_ClickEventHandler(syncButton_Click); optionsButton = GetButton("Fonlow.SyncML.Options", "Options", "Display the Options of sync", OutlookSyncMLAddIn.Properties.Resources.Settings16); optionsButton.Click += new Microsoft.Office.Core._CommandBarButtonEvents_ClickEventHandler(optionsButton_Click); syncBar.Visible = true; #if DEBUG logButton = GetButton("Fonlow.SyncML.Log", "Log", "Log window", null); logButton.Click += new Microsoft.Office.Core._CommandBarButtonEvents_ClickEventHandler(logButton_Click); #endif }
private void ThisAddIn_Startup(object sender, System.EventArgs e) { #region VSTO generated code InitDocument(); try { InitDocument(); LoadConfig(""); } catch (Exception ex) { BUS.CommonControl.AddLog("ErroLog", __documentDirectory + "\\Log", "Addin : " + ex.Message + "\n\t" + ex.Source + "\n\t" + ex.StackTrace); } try { Office.CommandBar imenu = (Office.CommandBar)Application.CommandBars["TVC-QD"]; //imenu.Delete(); if (imenu == null || imenu.Controls.Count == 0) { AddMenuItem(imenu); } } catch (Exception ex) { //System.Windows.Forms.MessageBox.Show(ex.Message); BUS.CommonControl.AddLog("ErroLog", __documentDirectory + "\\Log", "Addin : " + ex.Message + "\n\t" + ex.Source + "\n\t" + ex.StackTrace); AddMenuItem(null); } Application.SheetSelectionChange += new Microsoft.Office.Interop.Excel.AppEvents_SheetSelectionChangeEventHandler(Application_SheetSelectionChange); Application.SheetBeforeDoubleClick += new Microsoft.Office.Interop.Excel.AppEvents_SheetBeforeDoubleClickEventHandler(Application_SheetBeforeDoubleClick); #endregion }
private void AddToNotes(Microsoft.Office.Interop.Outlook.Inspector Inspector) { Outlook.NoteItem _ObjNoteItem = (Outlook.NoteItem)Inspector.CurrentItem; if (Inspector.CurrentItem is Outlook.NoteItem) { _ObjNoteItem = (Outlook.NoteItem)Inspector.CurrentItem; bool IsExists = false; foreach (Office.CommandBar _ObjCmd in Inspector.CommandBars) { if (_ObjCmd.Name == toolBarTagNote) { IsExists = true; _ObjCmd.Delete(); } } Office.CommandBar _ObjCommandBar = Inspector.CommandBars.Add(toolBarTagNote, Office.MsoBarPosition.msoBarBottom, false, true); _objNoteToolBarButton = (Office.CommandBarButton)_ObjCommandBar.Controls.Add(Office.MsoControlType.msoControlButton, 1, missing, missing, true); if (!IsExists) { _objNoteToolBarButton.Caption = "My Notes"; _objNoteToolBarButton.Style = Office.MsoButtonStyle.msoButtonIconAndCaptionBelow; _objNoteToolBarButton.FaceId = 500; _objNoteToolBarButton.Click += new Office._CommandBarButtonEvents_ClickEventHandler(_objNoteToolBarButton_Click); _ObjCommandBar.Visible = true; } } }
void Inspectors_NewInspector(Microsoft.Office.Interop.Outlook.Inspector Inspector) { Outlook.MailItem tmpMailItem = (Outlook.MailItem)Inspector.CurrentItem; if (Inspector.CurrentItem is Outlook.MailItem) { tmpMailItem = (Outlook.MailItem)Inspector.CurrentItem; bool exists = false; foreach (Office.CommandBar cmd in Inspector.CommandBars) { if (cmd.Name == "EAD") { //exists = true; cmd.Delete(); } } Office.CommandBar newMenuBar = Inspector.CommandBars.Add("EAD", Office.MsoBarPosition.msoBarTop, false, true); buttonOne = (Office.CommandBarButton)newMenuBar.Controls.Add(Office.MsoControlType.msoControlButton, 1, missing, missing, true); if (!exists) { buttonOne.Caption = "Scan this mail"; buttonOne.Style = Office.MsoButtonStyle.msoButtonCaption; buttonOne.FaceId = 1983; //Register send event handler buttonOne.Click += new Office._CommandBarButtonEvents_ClickEventHandler(buttonOne_Click); newMenuBar.Visible = true; } } }
private void AddMenuBar() { try { menuBar = this.Application.ActiveExplorer().CommandBars.ActiveMenuBar; newMenuBar = (Office.CommandBarPopup)menuBar.Controls.Add( Office.MsoControlType.msoControlPopup, missing, missing, missing, true); if (newMenuBar != null) { buttonOne = (Office.CommandBarButton) newMenuBar.Controls. Add(Office.MsoControlType.msoControlButton, System. Type.Missing, System.Type.Missing, 1, true); newMenuBar.Caption = "Highlight"; buttonOne.Style = Office.MsoButtonStyle.msoButtonIconAndCaption; buttonOne.Caption = "Highlight elad"; buttonOne.FaceId = 100; buttonOne.Tag = "c123"; buttonOne.Picture = getImage(); buttonOne.Click += ButtonOne_Click; newMenuBar.Visible = true; } } catch (Exception ex) { System.Windows.Forms.MessageBox.Show(ex.Message); } }
private void ThisAddIn_Startup(object sender, EventArgs e) { ExcelProperties.Instance.Worksheet = new WorksheetInteropWrapper((Excel.Worksheet)Globals.ThisAddIn.Application.ActiveSheet); ExcelProperties.Instance.Selection = new Selection { ColumnCount = 1, RowCount = 1, StartColumn = 1, StartRow = 1 }; _cellbar = Application.CommandBars["Cell"]; _button = (Office.CommandBarButton)_cellbar.FindControl(Office.MsoControlType.msoControlButton, 0, "MYRIGHTCLICKMENU", Missing.Value, Missing.Value); if (_button == null) { // add the button _button = (Office.CommandBarButton)_cellbar.Controls.Add(Office.MsoControlType.msoControlButton, Missing.Value, Missing.Value, _cellbar.Controls.Count, true); _button.Caption = "Quick Convert"; _button.BeginGroup = true; _button.DescriptionText = "Uses the actual ExcelTableConverter settings to convert the excel table"; _button.Picture = ConvertImage.GetIPictureDispImage(Properties.Resources.convert_icon_white_small); _button.Click += QuickConvertButton_Click; } //BaseTableConverter.CurrentConverter = BaseTableConverter.Converters.First().Value; Globals.ThisAddIn.Application.SheetSelectionChange += ApplicationOnSheetSelectionChange; Globals.ThisAddIn.Application.WorkbookActivate += ApplicationOnWorkbookActivate; Globals.ThisAddIn.Application.SheetActivate += ApplicationOnSheetActivate; }
private void AddToEmail(Microsoft.Office.Interop.Outlook.Inspector Inspector) { Outlook.MailItem _ObjMailItem = (Outlook.MailItem)Inspector.CurrentItem; System.Diagnostics.Debug.WriteLine("Add to Mail"); if (Inspector.CurrentItem is Outlook.MailItem) { System.Diagnostics.Debug.WriteLine("Add to Mail 1"); bool IsExists = false; foreach (Office.CommandBar _ObjCmd in Inspector.CommandBars) { if (_ObjCmd.Name == toolBarTagEmail) { IsExists = true; _ObjCmd.Delete(); } } Office.CommandBar _ObjCommandBar = Inspector.CommandBars.Add(toolBarTagEmail, Office.MsoBarPosition.msoBarTop, false, true); siGamalBarButton = (Office.CommandBarButton)_ObjCommandBar.Controls.Add(Office.MsoControlType.msoControlButton, 1, missing, missing, true); if (!IsExists) { System.Diagnostics.Debug.WriteLine("Add to Mail - 2"); siGamalBarButton.Caption = "SiGamal"; siGamalBarButton.Style = Office.MsoButtonStyle.msoButtonIconAndCaptionBelow; siGamalBarButton.FaceId = 500; siGamalBarButton.Click += new Office._CommandBarButtonEvents_ClickEventHandler(siGamalBarButton_Click); _ObjCommandBar.Visible = true; siGamalBarButton.Visible = true; } } }
//--------------------------------------------------------------------- //<Snippet5> private void AddPopUp() { commandBar = Application.CommandBars.Add("FormatText", Office.MsoBarPosition.msoBarPopup, missing, true); // Add a button and set the style, caption, icon and tag. boldText = (Office.CommandBarButton)commandBar.Controls.Add( 1); boldText.Style = Office.MsoButtonStyle.msoButtonCaption; boldText.Caption = "Bold"; boldText.FaceId = 113; boldText.Tag = "0"; // Add a button and set the style, caption, icon and tag. italicText = (Office.CommandBarButton)commandBar.Controls.Add( 1); italicText.Style = Office.MsoButtonStyle.msoButtonCaption; italicText.Caption = "Italic"; italicText.FaceId = 114; italicText.Tag = "1"; // Handle the click events with the ButtonClick procedure. boldText.Click += new Microsoft.Office.Core._CommandBarButtonEvents_ClickEventHandler(ButtonClick); italicText.Click += new Microsoft.Office.Core._CommandBarButtonEvents_ClickEventHandler(ButtonClick); ((Microsoft.Office.Interop.Word.Template) this.AttachedTemplate).Saved = true; }
// Create the menu, if it does not exist. private void AddMenuBar(Application appli) { Office.CommandBarPopup cmdBarControl = null; Office.CommandBar menubar = (Office.CommandBar)appli.CommandBars.ActiveMenuBar; int controlCount = menubar.Controls.Count; string menuCaption = MENU_CAPTION; // Add the menu. cmdBarControl = (Office.CommandBarPopup)menubar.Controls.Add( Office.MsoControlType.msoControlPopup, missing, missing, controlCount, missing); if (cmdBarControl != null) { cmdBarControl.Caption = menuCaption; cmdBarControl.Tag = MENU_ID; // Add the menu's commands. AddMenuCommand(cmdBarControl, ref menuCommand00, MENU_ITEM0_ID, MENU_ITEM0_CAPTION, new Microsoft.Office.Core._CommandBarButtonEvents_ClickEventHandler(menuCommand0_Click), MENU_ITEM0_FACEID); AddMenuCommand(cmdBarControl, ref menuCommand03, MENU_ITEM3_ID, MENU_ITEM3_CAPTION, new Microsoft.Office.Core._CommandBarButtonEvents_ClickEventHandler(menuCommand3_Click), MENU_ITEM3_FACEID); AddMenuCommand(cmdBarControl, ref menuCommand04, MENU_ITEM4_ID, MENU_ITEM4_CAPTION, new Microsoft.Office.Core._CommandBarButtonEvents_ClickEventHandler(menuCommand4_Click), MENU_ITEM4_FACEID); //AddMenuCommand(cmdBarControl, ref menuCommand05, MENU_ITEM5_ID, MENU_ITEM5_CAPTION, new Microsoft.Office.Core._CommandBarButtonEvents_ClickEventHandler(menuCommand5_Click), MENU_ITEM5_FACEID); //AddMenuCommand(cmdBarControl, ref menuCommand06, MENU_ITEM6_ID, MENU_ITEM6_CAPTION, new Microsoft.Office.Core._CommandBarButtonEvents_ClickEventHandler(menuCommand6_Click), MENU_ITEM6_FACEID); //AddMenuCommand(cmdBarControl, ref menuCommand07, MENU_ITEM7_ID, MENU_ITEM7_CAPTION, new Microsoft.Office.Core._CommandBarButtonEvents_ClickEventHandler(menuCommand7_Click), MENU_ITEM7_FACEID); //AddMenuCommand(cmdBarControl, ref menuCommand08, MENU_ITEM8_ID, MENU_ITEM8_CAPTION, new Microsoft.Office.Core._CommandBarButtonEvents_ClickEventHandler(menuCommand8_Click), MENU_ITEM8_FACEID); AddMenuCommand(cmdBarControl, ref menuCommand20, MENU_ITEM20_ID, MENU_ITEM20_CAPTION, new Microsoft.Office.Core._CommandBarButtonEvents_ClickEventHandler(menuCommand20_Click), MENU_ITEM20_FACEID); } }
private object AddContextMenu(string caption, string tag) { //application.CustomizationContext = application.ActiveDocument; Office.CommandBar commandBar = application.CommandBars["Text"]; // Remove if there is a duplicate already. Office.CommandBarButton control = (Office.CommandBarButton)commandBar.FindControl (Office.MsoControlType.msoControlButton, missing, tag, true, true); if ((control != null)) { contextButtons.Remove(tag); control.Delete(true); } //Create the new menu buttion and add it. Office.CommandBarButton button = (Office.CommandBarButton)commandBar.Controls.Add( Office.MsoControlType.msoControlButton); button.accName = caption; button.Caption = caption; button.Tag = tag; button.Click += ConextMenu_Click; contextButtons.Add(tag, button); return(button); }
/** * AddToolbar * Adds the toolbar and button to Excel **/ private void AddToolbar() { if (this.toolbar == null) { Office.CommandBars cmdBar = this.Application.CommandBars; this.toolbar = cmdBar.Add("MedPC Import Utility", Office.MsoBarPosition.msoBarTop, false, true); this.toolbar.Visible = true; } try { importButton = (Office.CommandBarButton)toolbar.Controls.Add(Office.MsoControlType.msoControlButton, missing, missing, missing, missing); importButton.Caption = "Quick-import data"; importButton.Tag = "MPC_Import"; importButton.Click += new Microsoft.Office.Core._CommandBarButtonEvents_ClickEventHandler(quickImportButton_click); importButton.Picture = getImage(); importButton = (Office.CommandBarButton)toolbar.Controls.Add(Office.MsoControlType.msoControlButton, missing, missing, missing, missing); importButton.Caption = "Import data"; importButton.Tag = "MPC_Import"; importButton.Click += new Microsoft.Office.Core._CommandBarButtonEvents_ClickEventHandler(importButton_click); importButton.Picture = getImage(); dataFilePath = "c:\\MED-PC IV\\Data"; xmlFilePath = "c:\\MED-PC IV\\MPC"; } catch (Exception e) { MessageBox.Show(e.Message); } }
// 如果菜单不存在则创建它. private void AddMenuBar() { try { Office.CommandBarPopup cmdBarControl = null; Office.CommandBar menubar = (Office.CommandBar)Application.CommandBars.ActiveMenuBar; int controlCount = menubar.Controls.Count; string menuCaption = "案例处理(&P)"; // Add the menu. cmdBarControl = (Office.CommandBarPopup)menubar.Controls.Add(Office.MsoControlType.msoControlPopup, missing, missing, controlCount, true); cmdBarControl.Tag = menuTag; if (cmdBarControl != null) { cmdBarControl.Caption = menuCaption; clearCaseAddressCommand = (Office.CommandBarButton)cmdBarControl.Controls.Add(Office.MsoControlType.msoControlButton, missing, missing, missing, true); clearCaseAddressCommand.Caption = "自动清理地址->楼盘(&S)"; clearCaseAddressCommand.Tag = "importCaseCommand"; clearCaseAddressCommand.FaceId = 0162; clearCaseAddressCommand.Click += new Microsoft.Office.Core._CommandBarButtonEvents_ClickEventHandler(clearCaseAddressCommand_Click); } } catch (Exception e) { MessageBox.Show(e.Message); } }
//public static bool AutoMaintainCustomTemplate = false; /// <summary> /// Makes the A new button. /// </summary> /// <param name="commandBar">The command bar.</param> /// <param name="caption">The caption.</param> /// <param name="faceID">The face ID.</param> /// <param name="beginGroup">if set to <c>true</c> [begin group].</param> /// <param name="clickHandler">The click handler.</param> /// <returns></returns> public static CommandBarButton MakeANewButton( Microsoft.Office.Core.CommandBar commandBar, string caption, Bitmap facePic, bool beginGroup, _CommandBarButtonEvents_ClickEventHandler clickHandler) { //Globals.ThisAddIn.PushOldTemplateAndSetCustom(); object missing = System.Reflection.Missing.Value; CommandBarButton newButton = null; try { newButton = MakeANewButton(commandBar, caption, beginGroup); if (newButton != null) { newButton.Click += clickHandler; newButton.Picture = (IPictureDisp)AxHost2.GettIPictureDispFromPicture(facePic); newButton.Mask = GetMask(facePic); } } catch (Exception ex) { LogHelper.DebugException("", ex); } return(newButton); }
AddButton( Office.CommandBarButton cbb, Office.CommandBar cbar, string name, Assembly asmbly, string bitMapName, string caption, string description, string toolTipText, Microsoft.Office.Core._CommandBarButtonEvents_ClickEventHandler eventHandler) { object missing = System.Reflection.Missing.Value; try { cbb = (Office.CommandBarButton)cbar.Controls.Add(Office.MsoControlType.msoControlButton, missing, missing, missing, missing); cbb.Style = Office.MsoButtonStyle.msoButtonIconAndCaption; cbb.Caption = caption; cbb.DescriptionText = description; cbb.Picture = ConvertImage.GetPicture(asmbly, bitMapName); cbb.TooltipText = toolTipText; cbb.Tag = Common.TAG_PREFIX + name; cbb.Click += eventHandler; return(cbb); } catch (Exception ex) { MessageBox.Show(ex.ToString()); // TODO: Add Logging throw ex; } }
public virtual void LoadMenu() { Office.CommandBars oCommandBars = null; try { oCommandBars = (Office.CommandBars)m_app.GetType().InvokeMember("CommandBars", BindingFlags.GetProperty, null, m_app, null); } catch (Exception) { } try { NewMenuBar = oCommandBars[cstrMenuTitle]; } catch (Exception) { // doesn't exist yet, so create it NewMenuBar = oCommandBars.Add(cstrMenuTitle, 1, missing, true); NewMenuBar.Visible = true; } ReleaseComObject(oCommandBars); }
// // Added from prior code // public void ListCommandBars(object objApp) // { // // Purpose: Lists all available command bars in // // this Office application. ////INSTANT C# NOTE: Commented this declaration since looping variables in 'foreach' loops are declared in the 'foreach' header in C# //// CommandBar objCommandBar = null; // string strResults = null; // System.Diagnostics.Debug.WriteLine("Command bars in this application:"); // foreach (Office.CommandBar objCommandBar in objApp.CommandBars) // { // System.Diagnostics.Debug.WriteLine(objCommandBar.Name + " (" + GetCBType(ref objCommandBar) + ")"); // } // } // public void ListCommandBarControls(Office.CommandBar objCommandBar) // { // // Purpose: Given a command bar, lists all of the controls // // on the command bar. ////INSTANT C# NOTE: Commented this declaration since looping variables in 'foreach' loops are declared in the 'foreach' header in C# //// CommandBarControl objCommandBarControl = null; // string strControlList = null; // strControlList = "Controls for the '" + objCommandBar.Name + "' command bar:" + System.Environment.NewLine; // foreach (Office.CommandBarControl objCommandBarControl in objCommandBar.Controls) // { // strControlList = strControlList + objCommandBarControl.Caption + " (" + GetCBCtlType(ref objCommandBarControl) + ")" + System.Environment.NewLine; // } // MessageBox.Show(strControlList); // } //public void ListButtonPicturesAndIDs(object objApp, short intStart, short intEnd) //{ // try // { // // Purpose: Given a starting and ending number, creates a // // command bar with pictures corresponding to the face IDs // // in the range of numbers provided. // Office.CommandBar objCommandBar = null; // Office.CommandBarButton objCommandBarButton = null; // short intButton = 0; //// On Error GoTo ListButtonPicturesAndIDs_Err // if (intStart > intEnd) // { // MessageBox.Show("Ending number must be smaller than starting number. " + "Please try again."); // return; // } // foreach (Office.CommandBar objCommandBarWithinLoop in objApp.CommandBars) // { // objCommandBar = objCommandBarWithinLoop; // if (objCommandBarWithinLoop.Name == "Button Pictures and IDs") // { // objCommandBarWithinLoop.Delete(); // } // } // objCommandBar = objApp.CommandBars.Add("Button Pictures and IDs", Missing.Value, Missing.Value, true); ////INSTANT C# NOTE: The ending condition of VB 'For' loops is tested only on entry to the loop. Instant C# has created a temporary variable in order to use the initial value of intEnd for every iteration: // short tempFor1 = intEnd; // for (intButton = intStart; intButton <= tempFor1; intButton++) // { // objCommandBarButton = objCommandBar.Controls.Add(Office.MsoControlType.msoControlButton, Missing.Value, Missing.Value, Missing.Value, true); // objCommandBarButton.FaceId = intButton; // objCommandBarButton.TooltipText = "FaceID = " + intButton; // } // objCommandBar.Visible = true; // ListButtonPicturesAndIDs_End: // return; // } // catch // { // //TODO: INSTANT C# TODO TASK: Calls to the VB 'Err' object are not converted by Instant C#: // switch (Err.Number) // { // case -2147467259: // Invalid FaceIDs. // MessageBox.Show("Invalid range of numbers for face IDs. " + "Please try again."); // break; // default: // //TODO: INSTANT C# TODO TASK: Calls to the VB 'Err' object are not converted by Instant C#: // MessageBox.Show("Error " + Err.Number + ": " + Err.Description); // break; // } // goto ListButtonPicturesAndIDs_End; // } //} // public void ListOutlookExplorerCommandBarNames(object objApp) // { // // Purpose: Lists all command bar names for the current explorer. // // Note: This code only works in Outlook! ////INSTANT C# NOTE: Commented this declaration since looping variables in 'foreach' loops are declared in the 'foreach' header in C# //// CommandBar objCommandBar = null; // //UPGRADE_WARNING: Couldn't resolve default property of object Application.ActiveExplorer. Click for more: 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="vbup1037"' // foreach (Office.CommandBar objCommandBar in objApp.ActiveExplorer.CommandBars) // { // System.Diagnostics.Debug.WriteLine(objCommandBar.Name); // } // } // public void ListCommandBarControlIDs(object objApp) // { // // Purpose: Lists all command bar control IDs for the // // current application. ////INSTANT C# NOTE: Commented this declaration since looping variables in 'foreach' loops are declared in the 'foreach' header in C# //// CommandBar objCommandBar = null; ////INSTANT C# NOTE: Commented this declaration since looping variables in 'foreach' loops are declared in the 'foreach' header in C# //// CommandBarControl objCommandBarControl = null; // // Replace the next line with: // // For Each objCommandBar In Application.ActiveExplorer.CommandBars <- For Outlook // // For Each objCommandBar In Application.VBE.CommandBars <- For Visual Basic Editor // foreach (Office.CommandBar objCommandBar in objApp.CommandBars) // { // foreach (Office.CommandBarControl objCommandBarControl in objCommandBar.Controls) // { // System.Diagnostics.Debug.WriteLine(objCommandBarControl.Caption + " " + objCommandBarControl.Id); // } // } // } //public bool ChangeCommandBarPosition(object objApp, string strCommandBarName, Office.MsoBarPosition msoPosition) //{ // try // { // // Purpose: Changes the position of a command bar. // // Accepts: // // strCommandBarName: The name of the command bar to change position. // // Returns: True if the command bar was successfully moved. // // On Error GoTo ChangeCommandBarPosition_Err // // Replace the next line of code with: // // Application.ActiveExplorer.CommandBars.Item(strCommandBarName).Position = _ // //msoPosition <- For Outlook // // Application.VBE.CommandBars.Item(strCommandBarName).Position = _ // //msoPosition <- For the Visual Basic Editor // objApp.CommandBars[strCommandBarName].Position = msoPosition; // ChangeCommandBarPosition_End: // return true; // } // catch // { // return false; // } //} //Public Sub CommandBarDocumenter(ByVal objApp As Object) // ' Purpose: Writes, to a text file, information about all // ' command bars in the current application. // ' You must first set a reference to the Microsoft Scripting Runtime // ' (scrrun.dll) for this code to run correctly. // ' Note: This code only works with Microsoft Office XP. // Dim objCommandBar As CommandBar // Dim strType As String // Dim strPosition As String // Dim strProtection As String // Dim objFileSaveDialog As Microsoft.Office.Core.FileDialog // Dim objFSO As Scripting.FileSystemObject // Dim objTextStream As Scripting.TextStream // Const SAVE_BUTTON As Short = -1 // objFileSaveDialog = objApp.FileDialog(MsoFileDialogType.msoFileDialogSaveAs) // objFileSaveDialog.Title = "Save Results As" // ' User clicked "Save" button. // If objFileSaveDialog.Show = SAVE_BUTTON Then // objFSO = New Scripting.FileSystemObject // objTextStream = objFSO.CreateTextFile(objFileSaveDialog.SelectedItems.Item(1)) // objTextStream.WriteLine("Name" & vbTab & "Type" & vbTab & "Enabled" & vbTab & "Visible" & vbTab & "Index" & vbTab & "Position" & vbTab & "Protection" & vbTab & "Row Index" & vbTab & "Top" & vbTab & "Height" & vbTab & "Left" & vbTab & "Width") // ' Replace the next line with: // ' For Each objCommandBar In Application.ActiveExplorer.CommandBars _ // '<- For Outlook // ' For Each objCommandBar In Application.VBE.CommandBars <- For _ // 'Visual Basic Editor // For Each objCommandBar In objApp.CommandBars // Select Case objCommandBar.Type // Case MsoBarType.msoBarTypeMenuBar // strType = "Menu Bar" // Case MsoBarType.msoBarTypeNormal // strType = "Normal" // Case MsoBarType.msoBarTypePopup // strType = "Pop-Up" // End Select // Select Case objCommandBar.Position // Case MsoBarPosition.msoBarBottom // strPosition = "Bottom" // Case MsoBarPosition.msoBarFloating // strPosition = "Floating" // Case MsoBarPosition.msoBarLeft // strPosition = "Left" // Case MsoBarPosition.msoBarMenuBar // strPosition = "Menu Bar" // Case MsoBarPosition.msoBarPopup // strPosition = "Pop-Up" // Case MsoBarPosition.msoBarRight // strPosition = "Right" // Case MsoBarPosition.msoBarTop // strPosition = "Top" // End Select // Select Case objCommandBar.Protection // Case MsoBarProtection.msoBarNoChangeDock // strProtection = "No Change Dock" // Case MsoBarProtection.msoBarNoChangeVisible // strProtection = "No Change Visible" // Case MsoBarProtection.msoBarNoCustomize // strProtection = "No Customize" // Case MsoBarProtection.msoBarNoHorizontalDock // strProtection = "No Horizontal Dock" // Case MsoBarProtection.msoBarNoMove // strProtection = "No Move" // Case MsoBarProtection.msoBarNoProtection // strProtection = "No Protection" // Case MsoBarProtection.msoBarNoResize // strProtection = "No Resize" // Case MsoBarProtection.msoBarNoVerticalDock // strProtection = "No Vertical Dock" // End Select // objTextStream.WriteLine(objCommandBar.Name & vbTab & strType & vbTab & objCommandBar.Enabled & vbTab & objCommandBar.Visible & vbTab & objCommandBar.Index & vbTab & strPosition & vbTab & strProtection & vbTab & objCommandBar.RowIndex & vbTab & objCommandBar.Top & vbTab & objCommandBar.Height & vbTab & objCommandBar.Left & vbTab & objCommandBar.Width) // Next objCommandBar // objTextStream.Close() // MsgBox("Results written to " & objFileSaveDialog.SelectedItems.Item(1) & ".") // End If //End Sub //Sub CommandBarControlDocumenter(ByVal objApp As Object) // ' Purpose: Writes, to a text file, information about all // ' command bar controls in the current application. // ' You must first set a reference to the Microsoft Scripting Runtime // ' (scrrun.dll) for this code to run correctly. // ' Note: This code only works with Microsoft Office XP. // Dim objCommandBar As CommandBar // Dim objCommandBarControl As CommandBarControl // Dim strOLEUsage As String // Dim strType As String // Dim objFileSaveDialog As Microsoft.Office.Core.FileDialog // Dim objFSO As Scripting.FileSystemObject // Dim objTextStream As Scripting.TextStream // Const SAVE_BUTTON As Short = -1 // objFileSaveDialog = objApp.FileDialog(MsoFileDialogType.msoFileDialogSaveAs) // objFileSaveDialog.Title = "Save Results As" // ' User clicked "Save" button. // If objFileSaveDialog.Show = SAVE_BUTTON Then // objFSO = New Scripting.FileSystemObject // objTextStream = objFSO.CreateTextFile(objFileSaveDialog.SelectedItems.Item(1)) // objTextStream.WriteLine("ID" & vbTab & "Index" & vbTab & "Caption" & vbTab & "Parent" & vbTab & "DescriptionText" & vbTab & "BuiltIn" & vbTab & "Enabled" & vbTab & "IsPriorityDropped" & vbTab & "OLEUsage" & vbTab & "Priority" & vbTab & "Tag" & vbTab & "TooltipText" & vbTab & "Type" & vbTab & "Visible" & vbTab & "Height" & vbTab & "Width") // ' Replace the next line with: // ' For Each objCommandBar In Application.ActiveExplorer.CommandBars <- For Outlook // ' For Each objCommandBar In Application.VBE.CommandBars _ // '<- For Visual Basic Editor // For Each objCommandBar In objApp.CommandBars // For Each objCommandBarControl In objCommandBar.Controls // Select Case objCommandBarControl.OLEUsage // Case MsoControlOLEUsage.msoControlOLEUsageBoth // strOLEUsage = "Both" // Case MsoControlOLEUsage.msoControlOLEUsageClient // strOLEUsage = "Client" // Case MsoControlOLEUsage.msoControlOLEUsageNeither // strOLEUsage = "Neither" // Case MsoControlOLEUsage.msoControlOLEUsageServer // strOLEUsage = "Server" // End Select // Select Case objCommandBarControl.Type // Case MsoControlType.msoControlActiveX // strType = "ActiveX" // Case MsoControlType.msoControlAutoCompleteCombo // strType = "Auto-Complete Combo Box" // Case MsoControlType.msoControlButton // strType = "Button" // Case MsoControlType.msoControlButtonDropdown // strType = "Drop-Down Button" // Case MsoControlType.msoControlButtonPopup // strType = "Popup Button" // Case MsoControlType.msoControlComboBox // strType = "Combo Box" // Case MsoControlType.msoControlCustom // strType = "Custom" // Case MsoControlType.msoControlDropdown // strType = "Drop-Down" // Case MsoControlType.msoControlEdit // strType = "Edit" // Case MsoControlType.msoControlExpandingGrid // strType = "Expanding Grid" // Case MsoControlType.msoControlGauge // strType = "Gauge" // Case MsoControlType.msoControlGenericDropdown // strType = "Generic Drop-Down" // Case MsoControlType.msoControlGraphicCombo // strType = "Graphic Combo Box" // Case MsoControlType.msoControlGraphicDropdown // strType = "Graphic Drop-Down" // Case MsoControlType.msoControlGraphicPopup // strType = "Popup Graphic" // Case MsoControlType.msoControlGrid // strType = "Grid" // Case MsoControlType.msoControlLabel // strType = "Label" // Case MsoControlType.msoControlLabelEx // strType = "LabelEx" // Case MsoControlType.msoControlOCXDropdown // strType = "OCX Drop-Down" // Case MsoControlType.msoControlPane // strType = "Pane" // Case MsoControlType.msoControlPopup // strType = "Popup" // Case MsoControlType.msoControlSpinner // strType = "Spinner" // Case MsoControlType.msoControlSplitButtonMRUPopup // strType = "Split Button MRU Popup" // Case MsoControlType.msoControlSplitButtonPopup // strType = "Button Popup" // Case MsoControlType.msoControlSplitDropdown // strType = "Split Drop-Down" // Case MsoControlType.msoControlSplitExpandingGrid // strType = "Split Expanding Grid" // Case MsoControlType.msoControlWorkPane // strType = "Work Pane" // End Select // objTextStream.WriteLine(objCommandBarControl.Id & vbTab & objCommandBarControl.Index & vbTab & objCommandBarControl.Caption & vbTab & objCommandBarControl.Parent.Name & vbTab & objCommandBarControl.DescriptionText & vbTab & objCommandBarControl.BuiltIn & vbTab & objCommandBarControl.Enabled & vbTab & objCommandBarControl.IsPriorityDropped & vbTab & strOLEUsage & vbTab & objCommandBarControl.Priority & vbTab & objCommandBarControl.Tag & vbTab & objCommandBarControl.TooltipText & vbTab & strType & vbTab & objCommandBarControl.Visible & vbTab & objCommandBarControl.Height & vbTab & objCommandBarControl.Width) // Next objCommandBarControl // Next objCommandBar // objTextStream.Close() // MsgBox("Results written to " & objFileSaveDialog.SelectedItems.Item(1) & ".") // End If //End Sub // public bool CBToolbarShow(object objApp, ref string strCBarName, ref bool blnVisible) // { // int templngPosition1 = Office.MsoBarPosition.msoBarTop; // return CBToolbarShow(objApp, ref strCBarName, ref blnVisible, ref templngPosition1); // } ////INSTANT C# NOTE: C# does not support optional parameters. Overloaded method(s) are created above. ////ORIGINAL LINE: Function CBToolbarShow(ByVal objApp As Object, ByRef strCBarName As String, ByRef blnVisible As Boolean, Optional ByRef lngPosition As Integer = MsoBarPosition.msoBarTop) As Boolean // public bool CBToolbarShow(object objApp, ref string strCBarName, ref bool blnVisible, ref int lngPosition) // { // bool tempCBToolbarShow = false; // try // { // // This procedure displays or hides the command bar specified in the // // strCBarName argument according to the value of the blnVisible // // argument. The optional lngPosition argument specifies where the // // command bar will appear on the screen. // Office.CommandBar cbrCmdBar = null; // // On Error GoTo CBToolbarShow_Err // cbrCmdBar = objApp.CommandBars(strCBarName); // // Show only toolbars. // if (cbrCmdBar.Type > Office.MsoBarType.msoBarTypeNormal) // return false; // // If Position argument is invalid, set to the default // // msoBarTop position. // if (lngPosition < Office.MsoBarPosition.msoBarLeft | lngPosition > MOffice.soBarPosition.msoBarMenuBar) // lngPosition = Office.MsoBarPosition.msoBarTop; // cbrCmdBar.Visible = blnVisible; // cbrCmdBar.Position = lngPosition; // tempCBToolbarShow = true; // CBToolbarShow_End: // return tempCBToolbarShow; // } // catch // { // tempCBToolbarShow = false; // goto CBToolbarShow_End; // } // return tempCBToolbarShow; // } //public static bool DeleteCommandBar(object objApp, ref string strCBarName) //{ // // Delete the command bar specified by strCBarName. If the // // command bar does not exist, an error will occur and that // // error is ignored here. // try // { // objApp.CommandBars(strCBarName).Delete(); // return true; // } // catch (Exception ex) // { // return false; // //throw; // } //} #endregion public string GetCBType(ref Office.CommandBar cbrBar) { // Returns a string representing the command bar type. string strCBType = null; //INSTANT C# NOTE: The following VB 'Select Case' included range-type or non-constant 'Case' expressions and was converted to C# 'if-else' logic: // Select Case cbrBar.Type //ORIGINAL LINE: Case MsoBarType.msoBarTypeNormal if (cbrBar.Type == Office.MsoBarType.msoBarTypeNormal) { strCBType = "Toolbar"; } //ORIGINAL LINE: Case MsoBarType.msoBarTypeMenuBar else if (cbrBar.Type == Office.MsoBarType.msoBarTypeMenuBar) { strCBType = "Menu bar"; } //ORIGINAL LINE: Case MsoBarType.msoBarTypePopup else if (cbrBar.Type == Office.MsoBarType.msoBarTypePopup) { strCBType = "Popup menu"; } return(strCBType); }
// Create the menu, if it does not exist. private void AddMenuBar() { try { Office.CommandBarPopup cmdBarControl = null; Office.CommandBar menubar = (Office.CommandBar)Application.CommandBars.ActiveMenuBar; int controlCount = menubar.Controls.Count; string menuCaption = "&New Menu"; // Add the menu. cmdBarControl = (Office.CommandBarPopup)menubar.Controls.Add( Office.MsoControlType.msoControlPopup, controlCount, true); if (cmdBarControl != null) { cmdBarControl.Caption = menuCaption; cmdBarControl.Tag = menuTag; // Add the menu command. menuCommand = (Office.CommandBarButton)cmdBarControl.Controls.Add( Office.MsoControlType.msoControlButton, true); menuCommand.Caption = "&New Menu Command"; menuCommand.Tag = "NewMenuCommand"; menuCommand.FaceId = 65; menuCommand.Click += new Microsoft.Office.Core._CommandBarButtonEvents_ClickEventHandler( menuCommand_Click); } } catch (Exception e) { MessageBox.Show(e.Message); } }
private void AddMenuBar() { try { menuBar = this.Application.ActiveExplorer().CommandBars.ActiveMenuBar; newMenuBar = (Office.CommandBarPopup)menuBar.Controls.Add(Office.MsoControlType.msoControlPopup, missing, missing, missing, true); if (newMenuBar != null) { newMenuBar.Caption = "New Menu"; buttonOne = (Office.CommandBarButton)newMenuBar.Controls. Add(Office.MsoControlType.msoControlButton, missing, missing, 1, true); buttonOne.Style = Office.MsoButtonStyle. msoButtonIconAndCaption; buttonOne.Caption = "Button One"; buttonOne.FaceId = 65; buttonOne.Tag = "c123"; //buttonOne.Click += new Office._CommandBarButtonEvents_ClickEventHandler(buttonOne_Click); newMenuBar.Visible = true; } } catch (Exception ex) { System.Windows.Forms.MessageBox.Show(ex.Message); } }
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); }
private void SetSPOCButton() { Microsoft.Office.Core.CommandBar cmdBar = this.Application.ActiveExplorer().CommandBars["Standard"]; //Try to get the existing Button spocButton = null; try { spocButton = (Microsoft.Office.Core.CommandBarButton)cmdBar.Controls["SPOC"]; } catch (System.Exception) { spocButton = null; } //If the button doesn't exist, create a new one if (spocButton == null) { spocButton = (Microsoft.Office.Core.CommandBarButton)cmdBar.Controls.Add(1, missing, missing, missing, false); } spocButton.Style = Microsoft.Office.Core.MsoButtonStyle.msoButtonIconAndCaption; spocButton.Caption = "SPOC"; spocButton.Tag = "SPOC"; spocButton.TooltipText = "SharePoint Outlook Connector"; ButtonHelper.GetInstance().SetButtonPicture(ref spocButton, ImageManager.GetInstance().GetSobiens20X20Image(), null); //Add a click handler for this button spocButton.Click += new Microsoft.Office.Core._CommandBarButtonEvents_ClickEventHandler(spocButton_Click); }
private void AddToolbar() { try { commandBar = Application.CommandBars["Test"]; } catch (ArgumentException) { // Toolbar named Test does not exist so we should create it. } if (commandBar == null) { // Add a commandbar named Test. commandBar = Application.CommandBars.Add("Test", 1, missing, true); } try { // Add a button to the command bar and an event handler. firstButton = (Office.CommandBarButton)commandBar.Controls.Add(1, missing, missing, missing, missing); firstButton.Style = Office.MsoButtonStyle.msoButtonCaption; firstButton.Caption = configInfo.MenuName; firstButton.Click += new Office._CommandBarButtonEvents_ClickEventHandler(ButtonClick); commandBar.Visible = true; } catch (ArgumentException e) { LogHelper.Error(e); } }
/// <summary> /// Set the CommandBar position from application property settings. /// </summary> /// <param name="settings"></param> internal void RestorePosition(Properties.Settings settings) { // Position the bar if (settings.BarPositionSaved) { _commandBar.Position = (Office.MsoBarPosition)settings.BarPosition; _commandBar.RowIndex = settings.BarRowIndex; _commandBar.Top = settings.BarTop; _commandBar.Left = settings.BarLeft; } else { Office.CommandBar standardBar = Find("standard"); if (standardBar != null) { int oldPos = standardBar.Left; _commandBar.RowIndex = standardBar.RowIndex; _commandBar.Left = standardBar.Left + standardBar.Width; _commandBar.Position = Office.MsoBarPosition.msoBarTop; standardBar.Left = oldPos; } else { _commandBar.Position = Office.MsoBarPosition.msoBarTop; } } }
/// <summary> /// Add a new CommandBar /// </summary> internal void Add() { if (_explorer == null) { return; } _commandBar = Find(_cmdBarName); if (_commandBar == null) { Office.CommandBars bars = _explorer.CommandBars; _commandBar = bars.Add(_cmdBarName, Office.MsoBarPosition.msoBarTop, false, true); } _commandBar.Visible = true; foreach (string btn in new string[] { "About", "Settings", "Decrypt", "Verify" }) { _buttons.Add(btn, (Office.CommandBarButton)_commandBar.Controls.Add(Office.MsoControlType.msoControlButton, Type.Missing, Type.Missing, 1, true)); _buttons[btn].Style = Office.MsoButtonStyle.msoButtonIconAndCaption; _buttons[btn].Caption = btn; _buttons[btn].Tag = "GnuPG" + btn; } // http://www.kebabshopblues.co.uk/2007/01/04/visual-studio-2005-tools-for-office-commandbarbutton-faceid-property/ _buttons["Decrypt"].FaceId = 718; _buttons["Verify"].FaceId = 719; _buttons["About"].FaceId = 700; _buttons["Settings"].FaceId = 2144; _buttons["Decrypt"].Picture = ImageConverter.Convert(Properties.Resources.lock_edit); _buttons["Verify"].Picture = ImageConverter.Convert(Properties.Resources.link_edit); _buttons["About"].Picture = ImageConverter.Convert(Properties.Resources.Logo); _buttons["Settings"].Picture = ImageConverter.Convert(Properties.Resources.database_gear); }
private void AttachApplication() { try { Console.WriteLine("USerControl1.cs AttachApplication"); if (file_name == null || file_name.Length == 0) { Console.WriteLine("Error: not valid file name provided", file_name); return; } Console.WriteLine("file name is: "); Console.WriteLine(file_name); //m_Workbook = GetActiveWorkbook(file_name); m_Workbook = RetrieveWorkbook(file_name); // Creation of the workbook object int count = 0; while (m_Workbook == null && count < 5) { Console.WriteLine("Couldn't retrieve workbook %", file_name); count++; m_Workbook = Open_Workbook(file_name); } if (m_Workbook != null) { Console.WriteLine("Workbook not null"); // Create the Excel.Application object m_XlApplication = (excel.Application)m_Workbook.Application; // Creation of the standard toolbar m_StandardCommandBar = m_XlApplication.CommandBars["Standard"]; m_StandardCommandBar.Position = core.MsoBarPosition.msoBarTop; m_StandardCommandBar.Visible = m_ToolBarVisible; //value may be false Console.WriteLine("tool bar bool: "); Console.WriteLine(m_ToolBarVisible); // Enable the OpenFile and New buttons foreach (core.CommandBarControl control in m_StandardCommandBar.Controls) { string name = control.get_accName(Missing.Value); if (name.Equals("Nouveau")) { ((core.CommandBarButton)control).Enabled = false; } if (name.Equals("Ouvrir")) { ((core.CommandBarButton)control).Enabled = false; } } } } catch { MessageBox.Show("Impossible to load Excel file"); return; } Console.WriteLine("END USerControl1.cs AttachApplication"); }
/// <summary> /// Creates the XWord menu. /// </summary> /// <param name="wordApplication">The <code>Word.Application</code>.</param> public void CreateXWordMenu(Word.Application wordApplication) { this.application = wordApplication; this.officeMenuBar = wordApplication.CommandBars.ActiveMenuBar; BuildMenus(); EnqueueEventHandlers(); DisableXWordMenus(); }
private void addMenuBar() { try { Office.CommandBarPopup cmdBarControl = null; Office.CommandBar menubar = (Office.CommandBar)Application.CommandBars.ActiveMenuBar; int controlCount = menubar.Controls.Count; string menuCaption = "PI D&ata Edit"; // Add the menu. cmdBarControl = (Office.CommandBarPopup)menubar.Controls.Add( Office.MsoControlType.msoControlPopup, missing, missing, controlCount, true); if (cmdBarControl != null) { cmdBarControl.Caption = menuCaption; // Add the menu command: Retrieve Data menuCommandGetPIData = (Office.CommandBarButton)cmdBarControl.Controls.Add( Office.MsoControlType.msoControlButton, missing, missing, missing, true); menuCommandGetPIData.Caption = "&Retrieve PI Data"; menuCommandGetPIData.Tag = menuTags.GetPIData.ToString(); menuCommandGetPIData.FaceId = 23; menuCommandGetPIData.Click += new Microsoft.Office.Core._CommandBarButtonEvents_ClickEventHandler( menuCommand_Click); // Add the menu command: Update Data menuCommandUpdateData = (Office.CommandBarButton)cmdBarControl.Controls.Add( Office.MsoControlType.msoControlButton, missing, missing, missing, true); menuCommandUpdateData.Caption = "&Update Data"; menuCommandUpdateData.Tag = menuTags.UpdateData.ToString(); menuCommandUpdateData.FaceId = 3; menuCommandUpdateData.Click += new Microsoft.Office.Core._CommandBarButtonEvents_ClickEventHandler( menuCommand_Click); // Add the menu command: About menuCommandAbout = (Office.CommandBarButton)cmdBarControl.Controls.Add( Office.MsoControlType.msoControlButton, missing, missing, missing, true); menuCommandAbout.BeginGroup = true; menuCommandAbout.Caption = "&About PI Data Edit"; menuCommandAbout.Tag = menuTags.AboutPIDataEdit.ToString(); menuCommandAbout.Click += new Microsoft.Office.Core._CommandBarButtonEvents_ClickEventHandler( menuCommand_Click); } } catch (Exception e) { MessageBox.Show(e.Message); } }
private void RemoveMenuItems() { // remove the RoundTable menu items try { // get the main menu bar //CommandBar menuBar = Utils.menuBar; //appOutlook.ActiveExplorer().CommandBars["Menu Bar"]; if (menuBar == null) { menuBar = appOutlook.ActiveExplorer().CommandBars["Menu Bar"]; } if (menuBar == null) { return; } // check for the Dommoni popup menu item foreach (CommandBarControl menuItem in menuBar.Controls) { if (menuItem.Caption == Utils.MENU_ITEM_ROUNDTABLE) { try { CommandBarPopup popup = (CommandBarPopup)menuItem; try { foreach (CommandBarControl item in popup.Controls) { item.Delete(false); } } catch (System.Exception) { // ignore. just means there are no sub items, perhaps // due to a previously failed cleanup } popup.Delete(false); } catch (System.Exception ex) { //ErrorHandler.PublishError(ex,logger); // TODO: Put back when this is solved ErrorHandler.PublishError(ex); } } } } catch (System.Exception ex) { //ErrorHandler.PublishError(ex, logger); // TODO: Put back when this is solved ErrorHandler.PublishError(ex); } }
/// <summary> /// Remove the GnuPG CommandBar, if any. /// </summary> /// <param name="explorer"></param> internal void Remove() { Office.CommandBar bar = Find(_cmdBarName); if (bar == null) { return; } bar.Delete(); }
private void BuildMenu() { _menuBar = this.ActiveExplorer().CommandBars.ActiveMenuBar; _helpMenuIndex = _menuBar.Controls.Count; _topMenu = (Office.CommandBarPopup)(_menuBar.Controls.Add(Office.MsoControlType.msoControlPopup, Type.Missing, Type.Missing, _helpMenuIndex, true)); _topMenu.Caption = "Add-in Tasks"; _topMenu.Visible = true; _settingsMenu = (Office.CommandBarButton)(_topMenu.Controls.Add(Office.MsoControlType.msoControlButton, Type.Missing, Type.Missing, Type.Missing, true)); _settingsMenu.Caption = "Growl Notification Settings..."; _settingsMenu.Visible = true; _settingsMenu.Enabled = true; _settingsMenu.Click += new Microsoft.Office.Core._CommandBarButtonEvents_ClickEventHandler(_settingsMenu_Click); }
private void AddToolbar() { if (_newToolBar == null) { var cmdBars = Application.ActiveExplorer().CommandBars; _newToolBar = cmdBars.Add("Create Contacts", Office.MsoBarPosition.msoBarTop, false, true); } try { var createCapContacts = (Office.CommandBarButton)_newToolBar.Controls .Add(1, missing, missing, missing, missing); createCapContacts.Style = Office .MsoButtonStyle.msoButtonIconAndCaption; createCapContacts.Caption = "Create capSpire Contacts"; Image logo = Image.FromFile( @"C:\Users\Craig\documents\visual studio 2013\Projects\ExecutiveAlert\ExecutiveAlert\Images\CapLogo.png"); createCapContacts.Picture = PictureConverter.ImageToPictureDisp(logo); createCapContacts.Width = 130; createCapContacts.Height = 130; createCapContacts.Tag = "createContacts"; if (_firstButton == null) { _firstButton = createCapContacts; _firstButton.Click += ButtonClick; } //Todo: second button idea var button2 = (Office.CommandBarButton)_newToolBar.Controls.Add(1); button2.Style = Office.MsoButtonStyle.msoButtonIconAndCaption; button2.Caption = "Button 2"; button2.Tag = "Button2"; _newToolBar.Visible = true; if (_secondButton == null) { _secondButton = button2; _secondButton.Click += ButtonClick; } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void AddToolbar() { if (newToolBar == null) { Office.CommandBars cmdBars = this.Application.ActiveExplorer().CommandBars; newToolBar = cmdBars.Add("NewToolBar", Office.MsoBarPosition.msoBarTop, false, true); } try { Office.CommandBarButton btnBanckleContacts = (Office.CommandBarButton)newToolBar.Controls .Add(1, missing, missing, missing, missing); btnBanckleContacts.Style = Office .MsoButtonStyle.msoButtonCaption; btnBanckleContacts.Caption = "Banckle Contacts"; btnBanckleContacts.Tag = "BanckleContacts"; if (this.firstButton == null) { this.firstButton = btnBanckleContacts; firstButton.Click += new Office. _CommandBarButtonEvents_ClickEventHandler (ButtonClick); } Office.CommandBarButton OutlookContacts = (Office .CommandBarButton)newToolBar.Controls.Add (1, missing, missing, missing, missing); OutlookContacts.Style = Office .MsoButtonStyle.msoButtonCaption; OutlookContacts.Caption = "Button 2"; OutlookContacts.Tag = "Button2"; newToolBar.Visible = true; if (this.secondButton == null) { this.secondButton = OutlookContacts; secondButton.Click += new Office. _CommandBarButtonEvents_ClickEventHandler (ButtonClick); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void AddToolbar() { const string btnEnumHierarchy = "Enumerate Hierarchy"; if (_newToolBar == null) { Office.CommandBars cmdBars = this.Application.ActiveExplorer().CommandBars; _newToolBar = cmdBars.Add("Test Bar", Office.MsoBarPosition.msoBarTop, false, true); } try { Office.CommandBarButton button_1 = (Office.CommandBarButton)_newToolBar.Controls .Add(1, missing, missing, missing, missing); button_1.Style = Office .MsoButtonStyle.msoButtonCaption; button_1.Caption = btnEnumHierarchy; button_1.Tag = btnEnumHierarchy; if (this._enumerateHiearchyButton == null) { this._enumerateHiearchyButton = button_1; _enumerateHiearchyButton.Click += new Office. _CommandBarButtonEvents_ClickEventHandler (EnumerateHierarchyClick); } Office.CommandBarButton button_2 = (Office .CommandBarButton)_newToolBar.Controls.Add (1, missing, missing, missing, missing); button_2.Style = Office .MsoButtonStyle.msoButtonCaption; button_2.Caption = "Move folder"; button_2.Tag = "Move folder"; _newToolBar.Visible = true; if (this._moveButton == null) { this._moveButton = button_2; _moveButton.Click += _moveButton_Click; } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
public void AddMenu() { try { mainMenuBar = ((Office.CommandBars)this.Application.ActiveWindow.CommandBars).ActiveMenuBar; } catch (Exception e) { string message = e.Message; return; } if (vstoAddInMenu != null) { vstoAddInMenu.Visible = true; return; } try { helpMenuIndex = mainMenuBar.Controls["Help"].Index; } catch (Exception) { helpMenuIndex = mainMenuBar.Controls.Count; } vstoAddInMenu = (Office.CommandBarPopup)mainMenuBar.Controls.Add(Office.MsoControlType.msoControlPopup, Type.Missing, Type.Missing, helpMenuIndex, true); vstoAddInMenu.Caption = "CancerGrid"; vstoAddInMenu.Visible = true; queryFormMenuItem = (Office.CommandBarButton)vstoAddInMenu.Controls.Add(Office.MsoControlType.msoControlButton, Type.Missing, Type.Missing, 1, 1); queryFormMenuItem.Style = Office.MsoButtonStyle.msoButtonCaption; queryFormMenuItem.Caption = "Query Service Control"; queryFormMenuItem.Click += new Office._CommandBarButtonEvents_ClickEventHandler(queryFormMenuItem_Click); cdeFormMenuItem = (Office.CommandBarButton)vstoAddInMenu.Controls.Add(Office.MsoControlType.msoControlButton, Type.Missing, Type.Missing, 1, 1); cdeFormMenuItem.Style = Office.MsoButtonStyle.msoButtonCaption; cdeFormMenuItem.Caption = "Create new Data Element"; cdeFormMenuItem.Click += new Office._CommandBarButtonEvents_ClickEventHandler(cdeFormMenuItem_Click); //menuAdded = true; }
public void OnStartupComplete(ref System.Array custom) { /* * When outlook is opened it loads a Menu if Outlook plugin is installed. * OpenERP - > Push, Partner ,Documents, Configuration */ Microsoft.Office.Interop.Outlook.Application app = null; try { app = new Microsoft.Office.Interop.Outlook.Application(); object omissing = System.Reflection.Missing.Value; menuBar = app.ActiveExplorer().CommandBars.ActiveMenuBar; ConfigManager config = new ConfigManager(); config.LoadConfigurationSetting(); OpenERPOutlookPlugin openerp_outlook = Cache.OpenERPOutlookPlugin; OpenERPConnect openerp_connect = openerp_outlook.Connection; try { if (openerp_connect.URL != null && openerp_connect.DBName != null && openerp_connect.UserId != null && openerp_connect.pswrd != "") { string decodpwd = Tools.DecryptB64Pwd(openerp_connect.pswrd); openerp_connect.Login(openerp_connect.DBName, openerp_connect.UserId, decodpwd); } } catch(Exception ) { MessageBox.Show("Unable to connect remote Server ' " + openerp_connect.URL + " '.", "OpenERP Connection",MessageBoxButtons.OK,MessageBoxIcon.Exclamation); } newMenuBar = (office.CommandBarPopup)menuBar.Controls.Add(office.MsoControlType.msoControlPopup, omissing, omissing, omissing, true); if (newMenuBar != null) { newMenuBar.Caption = "OpenERP"; newMenuBar.Tag = "My"; btn_open_partner = (office.CommandBarButton)newMenuBar.Controls.Add(office.MsoControlType.msoControlButton, omissing, omissing, 1, true); btn_open_partner.Style = office.MsoButtonStyle.msoButtonIconAndCaption; btn_open_partner.Caption = "Contact"; //Face ID will use to show the ICON in the left side of the menu. btn_open_partner.FaceId = 3710; newMenuBar.Visible = true; btn_open_partner.Click += new Microsoft.Office.Core._CommandBarButtonEvents_ClickEventHandler(this.btn_open_partner_Click); btn_open_document = (office.CommandBarButton)newMenuBar.Controls.Add(office.MsoControlType.msoControlButton, omissing, omissing, 2, true); btn_open_document.Style = office.MsoButtonStyle.msoButtonIconAndCaption; btn_open_document.Caption = "Documents"; //Face ID will use to show the ICON in the left side of the menu. btn_open_document.FaceId = 258; newMenuBar.Visible = true; btn_open_document.Click += new Microsoft.Office.Core._CommandBarButtonEvents_ClickEventHandler(this.btn_open_document_Click); btn_open_configuration_form = (office.CommandBarButton)newMenuBar.Controls.Add(office.MsoControlType.msoControlButton, omissing, omissing, 3, true); btn_open_configuration_form.Style = office.MsoButtonStyle.msoButtonIconAndCaption; btn_open_configuration_form.Caption = "Configuration"; //Face ID will use to show the ICON in the left side of the menu. btn_open_configuration_form.FaceId = 5644; newMenuBar.Visible = true; btn_open_configuration_form.Click += new Microsoft.Office.Core._CommandBarButtonEvents_ClickEventHandler(this.btn_open_configuration_form_Click); } } catch (Exception) { object oActiveExplorer; oActiveExplorer = applicationObject.GetType().InvokeMember("ActiveExplorer", BindingFlags.GetProperty, null, applicationObject, null); oCommandBars = (office.CommandBars)oActiveExplorer.GetType().InvokeMember("CommandBars", BindingFlags.GetProperty, null, oActiveExplorer, null); } }
/// <summary> /// Adds commandBars to Word Application /// </summary> private void AddToolbar() { // VSTO API uses object-wrapped booleans object falseValue = false; object trueValue = true; // Try to get a handle to an existing COMMANDBAR_NAME CommandBar try { m_CommandBar = Application.CommandBars[COMMANDBAR_NAME]; // If we found the CommandBar, then it's a permanent one we need to delete // Note: if the user has manually created a toolbar called COMMANDBAR_NAME it will get torched here if (m_CommandBar != null) { m_CommandBar.Delete(); } } catch { // Benign - the CommandBar didn't exist } // Create a temporary CommandBar named COMMANDBAR_NAME m_CommandBar = Application.CommandBars.Add(COMMANDBAR_NAME, Office.MsoBarPosition.msoBarTop, falseValue, trueValue); if (m_CommandBar != null) { // Load any saved toolbar position LoadToolbarPosition(); // Add our button to the command bar (as a temporary control) and an event handler. m_AlfrescoButton = (Office.CommandBarButton)m_CommandBar.Controls.Add(Office.MsoControlType.msoControlButton, missing, missing, missing, trueValue); if (m_AlfrescoButton != null) { m_AlfrescoButton.Style = Office.MsoButtonStyle.msoButtonIconAndCaption; m_AlfrescoButton.Caption = COMMANDBAR_BUTTON_CAPTION; m_AlfrescoButton.DescriptionText = COMMANDBAR_BUTTON_DESCRIPTION; m_AlfrescoButton.TooltipText = COMMANDBAR_BUTTON_DESCRIPTION; Bitmap bmpButton = new Bitmap(GetType(), "toolbar.ico"); m_AlfrescoButton.Picture = new ToolbarPicture(bmpButton); Bitmap bmpMask = new Bitmap(GetType(), "toolbar_mask.ico"); m_AlfrescoButton.Mask = new ToolbarPicture(bmpMask); m_AlfrescoButton.Tag = "AlfrescoButton"; // Finally add the event handler and make sure the button is visible m_AlfrescoButton.Click += new Microsoft.Office.Core._CommandBarButtonEvents_ClickEventHandler(m_AlfrescoButton_Click); } // Add the help button to the command bar (as a temporary control) and an event handler. m_HelpButton = (Office.CommandBarButton)m_CommandBar.Controls.Add(Office.MsoControlType.msoControlButton, missing, missing, missing, trueValue); if (m_HelpButton != null) { m_HelpButton.Style = Office.MsoButtonStyle.msoButtonIcon; m_HelpButton.DescriptionText = COMMANDBAR_HELP_DESCRIPTION; m_HelpButton.TooltipText = COMMANDBAR_HELP_DESCRIPTION; m_HelpButton.FaceId = 984; m_HelpButton.Tag = "AlfrescoHelpButton"; // Finally add the event handler and make sure the button is visible m_HelpButton.Click += new Microsoft.Office.Core._CommandBarButtonEvents_ClickEventHandler(m_HelpButton_Click); } // We need to find this toolbar later, so protect it from user changes m_CommandBar.Protection = Microsoft.Office.Core.MsoBarProtection.msoBarNoCustomize; m_CommandBar.Visible = true; } }
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; }
private void AddToolbar() { if (newToolBar == null) { Office.CommandBars cmdBars = this.Application.ActiveExplorer().CommandBars; //cmdBars. newToolBar = cmdBars.Add("Banckle CRM", Office.MsoBarPosition.msoBarTop, false, true); } try { //Office. btnBanckle = (Office.CommandBarButton)newToolBar.Controls.Add(1, missing, missing, missing, missing); btnBanckle.Style = Office.MsoButtonStyle.msoButtonIcon; btnBanckle.Caption = "Banckle CRM"; btnBanckle.Tag = "Banckle CRM"; btnBanckle.Picture = getImage(Properties.Resources.crm_16x16); btnBanckle.Click += new Office._CommandBarButtonEvents_ClickEventHandler(btnBanckleClick); btnSync = (Office.CommandBarButton)newToolBar.Controls.Add(1, missing, missing, missing, missing); btnSync.Style = Office.MsoButtonStyle.msoButtonIconAndCaption; btnSync.Caption = "Sync"; btnSync.Tag = "Sync"; btnSync.Picture = getImage(Properties.Resources.sync_16x16); btnSync.BeginGroup = true; btnSync.Click += new Office._CommandBarButtonEvents_ClickEventHandler(btnSyncClick); btnSettings = (Office.CommandBarButton)newToolBar.Controls.Add(1, missing, missing, missing, missing); btnSettings.Style = Office.MsoButtonStyle.msoButtonIconAndCaption; btnSettings.Caption = "Settings"; btnSettings.Picture = getImage(Properties.Resources.settings_16x16); btnSettings.Tag = "Settings"; newToolBar.Visible = true; btnSettings.Click += new Office._CommandBarButtonEvents_ClickEventHandler(btnSettingsClick); btnAbout = (Office.CommandBarButton)newToolBar.Controls.Add(1, missing, missing, missing, missing); btnAbout.Style = Office.MsoButtonStyle.msoButtonIconAndCaption; btnAbout.Caption = "About"; btnAbout.Picture = getImage(Properties.Resources.banckle_16x16); btnAbout.BeginGroup = true; btnAbout.Tag = "About"; btnAbout.Visible = true; btnAbout.Click += new Office._CommandBarButtonEvents_ClickEventHandler(btnAboutClick); } catch (Exception ex) { System.Windows.Forms.MessageBox.Show("Error:" + ex.Message, "Error"); } }
private void RemoveMenu() { try { cb = Application.CommandBars["Cell"]; foreach (Office.CommandBarControl ctrl in cb.Controls) { if (ctrl is Office.CommandBarPopup) { Office.CommandBarPopup popup = ctrl as Office.CommandBarPopup; if (popup.Caption == "QTP Framework" || popup.Caption == "Object repository") { popup.Delete(); } } if (ctrl is Office.CommandBarButton) { Office.CommandBarButton btn = ctrl as Office.CommandBarButton; if (btn.Caption == ACTION.CHECK.ToString() || btn.Caption == ACTION.FILL.ToString() || btn.Caption == ACTION.CLICK.ToString() || btn.Caption == ACTION.TEXT.ToString()) { btn.Delete(); } else if (btn.Caption == "Upload testcases to ALM" || btn.Caption == "Upload Framework Configuration") { btn.Delete(); } } } } catch (Exception ex) { System.Windows.Forms.MessageBox.Show(ex.Message); } }
private void SetupToolbar() { myToolbar = Application.CommandBars.Add( "Maui", Office.MsoBarPosition.msoBarTop, false, true ); if ( myToolbar == null ) { return; } AddReloadButton(); myToolbar.Visible = true; }
private void AttachApplication() { try { if (m_ExcelFileName == null || m_ExcelFileName.Length == 0) return; // Creation of the workbook object if ((m_Workbook = GetActiveWorkbook(m_ExcelFileName)) == null) return; // Create the Excel.Application object m_XlApplication = (Microsoft.Office.Interop.Excel.Application)m_Workbook.Application; // Creation of the standard toolbar m_StandardCommandBar = m_XlApplication.CommandBars["Standard"]; m_StandardCommandBar.Position = Officer.MsoBarPosition.msoBarTop; m_StandardCommandBar.Visible = m_ToolBarVisible; // Enable the OpenFile and New buttons foreach (Officer.CommandBarControl control in m_StandardCommandBar.Controls) { string name = control.get_accName(Missing.Value); if (name.Equals("Nouveau")) ((Officer.CommandBarButton)control).Enabled = false; if (name.Equals("Ouvrir")) ((Officer.CommandBarButton)control).Enabled = false; } } catch { MessageBox.Show("Impossible de charger le fichier Excel"); return; } }
/// <summary> /// Searches for existing XWord toolbar. /// </summary> /// <returns>TRUE if XWord toolbar was found.</returns> private bool FindXWordToolbar() { bool found = false; foreach (Office.CommandBar cmdBar in application.CommandBars) { if (cmdBar.Type != Office.MsoBarType.msoBarTypeMenuBar) { if (cmdBar.Name == "XWord2003 ToolBar") { xWordToolbar = cmdBar; found = true; break; } } } return found; }
/// <summary> /// <c>RemoveItopiaMenuBarIfExists</c> member function /// If the menu already exists, remove it. /// </summary> /// <param name="strParentMenuTag">Menu name as string</param> private void RemoveItopiaMenuBarIfExists(string strParentMenuTag) { try { menuBarItopia = this.Application.ActiveExplorer().CommandBars.ActiveMenuBar; Office.CommandBarPopup foundMenu = (Office.CommandBarPopup)menuBarItopia.FindControl( Office.MsoControlType.msoControlPopup, System.Type.Missing, strParentMenuName, true, true); if (foundMenu != null) { foundMenu.Delete(true); } } catch (Exception ex) { } }
/// <summary> /// <c>CreateParentMenu</c> member function /// Method to create Parent Menu ie At the Top /// </summary> /// <param name="strParentMenuTag"></param> /// <param name="strCaption"></param> /// <returns></returns> private bool CreateParentMenu(string strParentMenuTag, string strCaption) { try { //Define the existent Menu Bar menuBarItopia = this.Application.ActiveExplorer().CommandBars.ActiveMenuBar; //Add new ITopia menu bar to active menubar menuBarSharePoint = (Office.CommandBarButton)menuBarItopia.Controls.Add( Office.MsoControlType.msoControlButton, missing, missing, missing, false); //If I dont find the newMenuBar, I add it if (menuBarSharePoint != null) { //Add caption and tag menuBarSharePoint.Caption = strCaption; menuBarSharePoint.Tag = strParentMenuTag; //Create SharePoint menu under ItopiaToola Menu //menuBarConnectionProperties = (Office.CommandBarPopup)menuBarSharePoint.Controls.Add(Office.MsoControlType.msoControlPopup, missing, missing, 1, true); //menuBarConnectionProperties.Caption = "Sharepoint"; //menuBarConnectionProperties.Tag = "SharePoint"; //Add button control to SharePoint popup menu btnOptions = (Office.CommandBarButton)menuBarItopia.Controls.Add(Office.MsoControlType.msoControlButton, missing, missing, 1, true); btnOptions.Style = Office.MsoButtonStyle.msoButtonIconAndCaption; btnOptions.Caption = "Options"; btnOptions.FaceId = 630; btnOptions.Tag = "Options"; btnOptions.Visible = true; btnOptions.Click += new Microsoft.Office.Core._CommandBarButtonEvents_ClickEventHandler(btnOptions_Click); //Add button control to SharePoint popup menu btnNewConnection = (Office.CommandBarButton)menuBarItopia.Controls.Add(Office.MsoControlType.msoControlButton, missing, missing, 1, true); btnNewConnection.Style = Office.MsoButtonStyle.msoButtonIconAndCaption; btnNewConnection.Caption = "New Connection"; btnNewConnection.FaceId = 611; btnNewConnection.Tag = "New Connection"; btnNewConnection.Visible = true; btnNewConnection.Click += new Microsoft.Office.Core._CommandBarButtonEvents_ClickEventHandler(btnNewConnection_Click); //Add button control to SharePoint popup menu btnConnectionProperties = (Office.CommandBarButton)menuBarItopia.Controls.Add(Office.MsoControlType.msoControlButton, missing, missing, 1, true); btnConnectionProperties.Style = Office.MsoButtonStyle.msoButtonIconAndCaption; btnConnectionProperties.Caption = "Connection Properties"; btnConnectionProperties.FaceId = 610; btnConnectionProperties.Tag = "Connection Properties"; btnConnectionProperties.Visible = true; btnConnectionProperties.Click += new Microsoft.Office.Core._CommandBarButtonEvents_ClickEventHandler(btnConnectionProperties_Click); return true; } } catch (Exception ex) { throw ex; } return false; }
private void newExplorer_Event(Outlook.Explorer new_Explorer) { ((Outlook._Explorer)new_Explorer).Activate(); newToolBar = null; AddToolbar(); }
void InfoPahtApplicationEvents_WindowActivate(InfoPath._XDocument pDocument, InfoPath.Window pWindow) { mainMenuBar = ((Office.CommandBars)this.Application.ActiveWindow.CommandBars).ActiveMenuBar; if (vstoAddInMenu != null) { vstoAddInMenu.Visible = true; } else { AddMenu(); } foreach (Microsoft.Office.Tools.CustomTaskPane taskpane in this.CustomTaskPanes) { if (taskpane.Title == "Query Service Control") { taskpane.Visible = true; return; } } AddQueryServiceTaskPane(this.Application.ActiveWindow); }
private void ThisAddIn_Startup(object sender, System.EventArgs e) { try { test(); menuBar = this.Application.ActiveExplorer().CommandBars.ActiveMenuBar; RemoveMenubar(); AddMenuBar(); _Explorer = (Outlook.ExplorerClass)this.Application.ActiveExplorer(); _CommandBars = _Explorer.CommandBars; _CommandBars.OnUpdate += new Microsoft.Office.Core._CommandBarsEvents_OnUpdateEventHandler(_CommandBars_OnUpdate); buttonConfig.Click += new Office._CommandBarButtonEvents_ClickEventHandler(buttonConfig_Click); //MessageBox.Show("The Outlook add-in has been deployed successfully."); } catch (Exception ex) { FormError bob = new FormError(e.ToString(), "Erreur lors du deploiement du plugin." + System.Environment.NewLine + "Veuillez redémarrez le programme, réessayez ou contactez l'administrateur si le problème persiste."); bob.ShowDialog(); System.Diagnostics.Trace.TraceError("Problème deploiement plugin :" + ex); using (System.IO.StreamWriter file = new System.IO.StreamWriter(appDataFolterPath + "\\" + folderConfigName + @"\tmp\error.log", true)) { file.WriteLine(ex + "\n\t\n\t"); file.Close(); } } }
/// <summary> /// Creates the tooblar, adds the buttons and enqueues click events handlers. /// </summary> private void BuildToolbar() { bool toolbarExists = FindXWordToolbar(); if (toolbarExists) { xWordToolbar.Delete(); } try { xWordToolbar = application.CommandBars.Add( "XWord2003 ToolBar", Office.MsoBarPosition.msoBarTop, false, true); xWordToolbar.Enabled = true; xWordToolbar.Visible = false; xWordToolbar.Protection = Office.MsoBarProtection.msoBarNoCustomize; xWordToolbar.Name = "XWord2003 ToolBar"; if (xWordToolbar != null) { btnNew = (Office.CommandBarButton)xWordToolbar.Controls.Add( Office.MsoControlType.msoControlButton, missing, missing, missing, true); btnNew.Caption = "New..."; btnNew.FaceId = 1; btnNew.Enabled = false; btnNew.Visible = true; btnNew.Style = Office.MsoButtonStyle.msoButtonIconAndCaption; btnNew.Tag = "XWord2003ToolbarBtnNew"; btnNew.Click += new Microsoft.Office.Core._CommandBarButtonEvents_ClickEventHandler(btnNew_Click); btnOpen = (Office.CommandBarButton)xWordToolbar.Controls.Add( Office.MsoControlType.msoControlButton, missing, missing, missing, true); btnOpen.Caption = "Open XWiki page"; btnOpen.FaceId = 1; btnOpen.Enabled = false; btnOpen.Visible = true; btnOpen.Style = Office.MsoButtonStyle.msoButtonIconAndCaption; btnOpen.Tag = "XWord2003ToolbarBtnOpen"; btnOpen.Click += new Microsoft.Office.Core._CommandBarButtonEvents_ClickEventHandler(btnOpen_Click); btnPublish = (Office.CommandBarButton)xWordToolbar.Controls.Add( Office.MsoControlType.msoControlButton, missing, missing, missing, true); btnPublish.Caption = "Publish XWiki page"; btnPublish.FaceId = 1; btnPublish.Enabled = false; btnPublish.Visible = true; btnPublish.Style = Office.MsoButtonStyle.msoButtonIconAndCaption; btnPublish.Tag = "XWord2003ToolbarBtnPublish"; btnPublish.Click += new Microsoft.Office.Core._CommandBarButtonEvents_ClickEventHandler(btnPublish_Click); btnViewInBrowser = (Office.CommandBarButton)xWordToolbar.Controls.Add( Office.MsoControlType.msoControlButton, missing, missing, missing, true); btnViewInBrowser.Caption = "View in Browser"; btnViewInBrowser.FaceId = 1; btnViewInBrowser.Enabled = false; btnViewInBrowser.Visible = true; btnViewInBrowser.Style = Office.MsoButtonStyle.msoButtonIconAndCaption; btnViewInBrowser.Tag = "XWord2003ToolbarBtnViewInBrowser"; btnViewInBrowser.Click += new Microsoft.Office.Core._CommandBarButtonEvents_ClickEventHandler(btnViewInBrowser_Click); btnViewAttachments = (Office.CommandBarButton)xWordToolbar.Controls.Add( Office.MsoControlType.msoControlButton, missing, missing, missing, true); btnViewAttachments.Caption = "View Attachments"; btnViewAttachments.FaceId = 1; btnViewAttachments.Enabled = false; btnViewAttachments.Visible = true; btnViewAttachments.Style = Office.MsoButtonStyle.msoButtonIconAndCaption; btnViewAttachments.Tag = "XWord2003ToolbarBtnViewAttachments"; btnViewAttachments.BeginGroup = true; btnViewAttachments.Click += new Microsoft.Office.Core._CommandBarButtonEvents_ClickEventHandler(btnViewAttachments_Click); btnAddAttachment = (Office.CommandBarButton)xWordToolbar.Controls.Add( Office.MsoControlType.msoControlButton, missing, missing, missing, true); btnAddAttachment.Caption = "Add Attachment"; btnAddAttachment.FaceId = 1; btnAddAttachment.Enabled = false; btnAddAttachment.Visible = true; btnAddAttachment.Style = Office.MsoButtonStyle.msoButtonIconAndCaption; btnAddAttachment.Tag = "XWord2003ToolbarBtnAddAttachment"; btnAddAttachment.Click += new Microsoft.Office.Core._CommandBarButtonEvents_ClickEventHandler(btnAddAttachment_Click); btnXWordSettings = (Office.CommandBarButton)xWordToolbar.Controls.Add( Office.MsoControlType.msoControlButton, missing, missing, missing, true); btnXWordSettings.Caption = "XWord Settings"; btnXWordSettings.FaceId = 1; btnXWordSettings.Enabled = true; btnXWordSettings.Visible = true; btnXWordSettings.Style = Office.MsoButtonStyle.msoButtonIconAndCaption; btnXWordSettings.Tag = "XWord2003ToolbarBtnXWordSettings"; btnXWordSettings.BeginGroup = true; btnXWordSettings.Click += new Microsoft.Office.Core._CommandBarButtonEvents_ClickEventHandler(btnXWordSettings_Click); btnAboutXWord = (Office.CommandBarButton)xWordToolbar.Controls.Add( Office.MsoControlType.msoControlButton, missing, missing, missing, true); btnAboutXWord.Caption = "About XWord"; btnAboutXWord.FaceId = 1; btnAboutXWord.Enabled = true; btnAboutXWord.Visible = true; btnAboutXWord.Style = Office.MsoButtonStyle.msoButtonIconAndCaption; btnAboutXWord.Tag = "XWord2003ToolbarBtnAbout"; btnAboutXWord.BeginGroup = true; btnAboutXWord.Click += new Microsoft.Office.Core._CommandBarButtonEvents_ClickEventHandler(btnAboutXWord_Click); xWordToolbar.Visible = true; } } catch { } }
private void AddMenu() { cb = Application.CommandBars["Cell"]; RemoveMenu(); menu = (Office.CommandBarPopup)cb.Controls.Add(Office.MsoControlType.msoControlPopup, missing, missing, missing, missing); menu.Caption = "QTP Framework"; menu_alm = (Office.CommandBarPopup)menu.Controls.Add(Office.MsoControlType.msoControlPopup, missing, missing, missing, missing); menu_alm.Caption = "HP ALM"; btnConnect = (Office.CommandBarButton)menu_alm.Controls.Add(1, missing, missing, missing, missing); btnConnect.TooltipText = "Connect to " + Framework.Connection.Repository.ToString() + " repository."; btnConnect.Click += new Office._CommandBarButtonEvents_ClickEventHandler(btnConnect_Click); if (Framework.Ready) { btnConnect.Caption = "Disconnect"; btnUploadProcess = (Office.CommandBarButton)menu_alm.Controls.Add(1, missing, missing, missing, missing); btnUploadProcess.TooltipText = "Upload Workbook"; btnUploadProcess.Caption = "Upload Workbook"; btnUploadProcess.Click += new Office._CommandBarButtonEvents_ClickEventHandler(btnUploadProcess_Click); btnUpload = (Office.CommandBarButton)menu_alm.Controls.Add(1, missing, missing, missing, missing); btnUpload.TooltipText = "Upload Testcases"; btnUpload.Caption = "Upload Testcase"; btnUpload.Click += btnUpload_Click; btnUploadConfig = (Office.CommandBarButton)menu_alm.Controls.Add(1, missing, missing, missing, missing); btnUploadConfig.TooltipText = "Repository Manager"; btnUploadConfig.Caption = "Repository Manager"; btnUploadConfig.Click += new Office._CommandBarButtonEvents_ClickEventHandler(btnConfig_Click); //menu_config = (Office.CommandBarPopup)menu.Controls.Add(Office.MsoControlType.msoControlPopup, missing, missing, missing, missing); //menu_config.Caption = "Configuration"; //btnExport = (Office.CommandBarButton)menu_config.Controls.Add(1, missing, missing, missing, missing); //btnExport.TooltipText = "Export Objects to QTP Framework Configuration"; //btnExport.Caption = "Upload Objects"; //btnExport.Click += new Office._CommandBarButtonEvents_ClickEventHandler(btnExport_Click); //btnManage = (Office.CommandBarButton)menu_config.Controls.Add(1, missing, missing, missing, missing); //btnManage.TooltipText = "Manage QTP Framework Configuration"; //btnManage.Caption = "Manage configuration"; //btnManage.Click += new Office._CommandBarButtonEvents_ClickEventHandler(btnManage_Click); } else { btnConnect.Caption = "Connect"; } /// btnCheck = (Office.CommandBarButton)menu.Controls.Add(1, missing, missing, missing, missing); btnCheck.TooltipText = "check a value of a screen object"; btnCheck.Caption = ACTION.CHECK.ToString(); btnCheck.Click += button_Click; /// btnFill = (Office.CommandBarButton)menu.Controls.Add(1, missing, missing, missing, missing); btnFill.TooltipText = "fill a value in a screen object"; btnFill.Caption = ACTION.FILL.ToString(); btnFill.Click += button_Click; /// btnText = (Office.CommandBarButton)menu.Controls.Add(1, missing, missing, missing, missing); btnText.TooltipText = "Check text on a screen"; btnText.Caption = ACTION.TEXT.ToString(); ; btnText.Click += button_Click; /// btnClick = (Office.CommandBarButton)menu.Controls.Add(1, missing, missing, missing, missing); btnClick.TooltipText = "Click on a screen object"; btnClick.Caption = ACTION.CLICK.ToString(); ; btnClick.Click += button_Click; /// btnScreen = (Office.CommandBarButton)menu.Controls.Add(1, missing, missing, missing, missing); btnScreen.TooltipText = "Screen"; btnScreen.Caption = "Screen"; btnScreen.Click += button_Click; }
/// <summary> /// 添加智真会议工具栏 /// </summary> private void AddMenuBar() { try { menuBar = this.Application.ActiveExplorer().CommandBars.ActiveMenuBar; newMenuBar = (Office.CommandBarPopup)menuBar.Controls.Add(Office.MsoControlType.msoControlPopup, missing, missing, 2, true); if (newMenuBar != null) { newMenuBar.Caption = GlobalResourceClass.getMsg("BTN_CREATE_TP_CONF"); newMenuBar.Tag = menuTag; btnSchedule = (Office.CommandBarButton)newMenuBar.Controls.Add(Office.MsoControlType.msoControlButton, missing, missing, 1, true); btnSchedule.Style = Office.MsoButtonStyle.msoButtonIconAndCaption; btnSchedule.Caption = GlobalResourceClass.getMsg("BTN_CREATE_TP_CONF"); btnSchedule.FaceId = 65; btnSchedule.Picture = ConvertImage.getImage(Properties.Resources.favicon);//new stdole.IPictureDisp; btnSchedule.Tag = "TP001"; btnSchedule.Click += new _CommandBarButtonEvents_ClickEventHandler(TPEventHandlers.btnSchedule_Click); // btnConfSettings = (Office.CommandBarButton)newMenuBar.Controls.Add(Office.MsoControlType.msoControlButton, missing, missing, missing, true); btnConfSettings.Style = Office.MsoButtonStyle.msoButtonIconAndCaption; btnConfSettings.Caption = GlobalResourceClass.getMsg("BTN_CONF_SETTINGS"); btnConfSettings.FaceId = 66; btnConfSettings.Picture = ConvertImage.getImage(Properties.Resources.setting_meeting1); btnConfSettings.Tag = "TP002"; btnConfSettings.Click += new _CommandBarButtonEvents_ClickEventHandler(TPEventHandlers.btnConfSettings_Click); // btnSysSettings = (Office.CommandBarButton)newMenuBar.Controls.Add(Office.MsoControlType.msoControlButton, missing, missing, missing, true); btnSysSettings.Style = Office.MsoButtonStyle.msoButtonIconAndCaption; btnSysSettings.Caption = GlobalResourceClass.getMsg("BTN_SYSTEM_SETTINGS"); btnSysSettings.FaceId = 67; btnSysSettings.Picture = ConvertImage.getImage(Properties.Resources.setting_order1); btnSysSettings.Tag = "TP003"; btnSysSettings.Click += new _CommandBarButtonEvents_ClickEventHandler(TPEventHandlers.btnSysSettings_Click); // btnHelp = (Office.CommandBarButton)newMenuBar.Controls.Add(Office.MsoControlType.msoControlButton, missing, missing, missing, true); btnHelp.Style = Office.MsoButtonStyle.msoButtonIconAndCaption; btnHelp.Caption = GlobalResourceClass.getMsg("BTN_HELP"); btnHelp.FaceId = 68; btnHelp.Picture = ConvertImage.getImage(Properties.Resources.QuestionMark1); btnHelp.Tag = "TP004"; btnHelp.Click += new _CommandBarButtonEvents_ClickEventHandler(TPEventHandlers.btnHelp_Click); // btnAbout = (Office.CommandBarButton)newMenuBar.Controls.Add(Office.MsoControlType.msoControlButton, missing, missing, missing, true); btnAbout.Style = Office.MsoButtonStyle.msoButtonIconAndCaption; btnAbout.Caption = GlobalResourceClass.getMsg("BTN_ABOUT"); btnAbout.FaceId = 69; btnAbout.Picture = ConvertImage.getImage(Properties.Resources.about1); btnAbout.Tag = "TP005"; btnAbout.Click += new _CommandBarButtonEvents_ClickEventHandler(TPEventHandlers.btnAbout_Click); newMenuBar.Visible = true; } } catch (System.Exception ex) { MessageBox.Show(ex.Message); } }
private void CreateTask_Startup(object sender, System.EventArgs e) { try { if (tisToolBar == null) { tisToolBar = Application.ActiveExplorer().CommandBars.Add("TIS", Office.MsoBarPosition.msoBarTop, false, true); // Add Button to Toolbar tisCreateTaskToolBarButton = (Office.CommandBarButton)tisToolBar.Controls.Add(Office.MsoControlType.msoControlButton, missing, missing,1, true); tisCreateTaskToolBarButton.Caption = "Create Task"; tisCreateTaskToolBarButton.Click += new Office._CommandBarButtonEvents_ClickEventHandler(tisCreateTaskToolBarButton_Click); tisToolBar.Visible = true; } } catch (System.Exception exception1) { System.Exception thisException = exception1; Management.ShowException(thisException); } }
//public PPTPaneManager(string[] modes) : this(modes, new PPTLibrary.PPT()) { } public PPTPaneManager(string[] modes, PPTLibrary.PPT ppt) { if (modes == null) modes = DEFAULT_MODES; if (ppt == null) throw new ArgumentNullException("ppt"); this.myPPT = ppt; // Set up the list of modes; should match the ordering of the buttons in the mode button bars. this.myModes = new string[modes.Length + 1]; System.Array.Copy(modes, 0, this.myModes, 1, modes.Length); this.myModes[0] = DEFAULT_MODE; // Set up the bars. this.myPresentationModeBar = this.myPPT.AddCommandBar(PRESENTATION_MODEBAR_NAME, Core.MsoBarPosition.msoBarTop, true, true); this.myShapeModeBar = this.myPPT.AddCommandBar(SHAPE_MODEBAR_NAME, Core.MsoBarPosition.msoBarTop, true, true); // Add the "base" buttons Core.CommandBarButton button = (Core.CommandBarButton) this.myPPT.AddControl(this.myPresentationModeBar, Core.MsoControlType.msoControlButton, "Projected View"); button.Click += new Core._CommandBarButtonEvents_ClickEventHandler(this.HandlePresentationModeClick); button.TooltipText = "Switch to base mode in which only unrestricted objects are visible."; button.Style = Core.MsoButtonStyle.msoButtonWrapCaption; button = (Core.CommandBarButton) this.myPPT.AddControl(this.myShapeModeBar, Core.MsoControlType.msoControlButton, "Unrestricted"); button.Click += new Core._CommandBarButtonEvents_ClickEventHandler(this.HandleShapeModeClick); button.TooltipText = "Set shape(s) to be unrestricted, making them visible in all modes."; button.Style = Core.MsoButtonStyle.msoButtonWrapCaption; foreach (string mode in modes) { button = (Core.CommandBarButton) this.myPPT.AddControl(this.myPresentationModeBar, Core.MsoControlType.msoControlButton, mode + " View"); button.Click += new Core._CommandBarButtonEvents_ClickEventHandler(this.HandlePresentationModeClick); button.TooltipText = "Toggle '" + mode + " View'.\nOnly unrestricted objects and objects restricted to '" + mode + " View' are visible in '" + mode + " View'."; button.Style = Core.MsoButtonStyle.msoButtonWrapCaption; button = (Core.CommandBarButton) this.myPPT.AddControl(this.myShapeModeBar, Core.MsoControlType.msoControlButton, mode + " Note"); button.Click += new Core._CommandBarButtonEvents_ClickEventHandler(this.HandleShapeModeClick); button.TooltipText = "Toggle restriction of shape(s) to '" + mode + "' mode.\nUnrestricted objects are visible in all modes.\nRestricted objects are visible only in the modes to which they are restricted."; button.Style = Core.MsoButtonStyle.msoButtonWrapCaption; } // Hook to relevant PPT events. this.myPPT.App.WindowActivate += new PowerPoint.EApplication_WindowActivateEventHandler(this.HandleWindowActivate); this.myPPT.App.WindowDeactivate += new PowerPoint.EApplication_WindowDeactivateEventHandler(this.HandleWindowDeactivate); this.myPPT.App.WindowSelectionChange += new PowerPoint.EApplication_WindowSelectionChangeEventHandler(this.HandleWindowSelectionChange); // New presentation event doesn't seem to be working in pre-SP2 (or possibly SP1). this.myPPT.App.AfterNewPresentation += new PowerPoint.EApplication_AfterNewPresentationEventHandler(this.HandleAfterNewPresentation); this.myPPT.App.PresentationSave += new PowerPoint.EApplication_PresentationSaveEventHandler(this.HandlePresentationSave); this.myPPT.App.AfterPresentationOpen += new PowerPoint.EApplication_AfterPresentationOpenEventHandler(this.HandleAfterPresentationOpen); this.myPPT.App.PresentationNewSlide += new PowerPoint.EApplication_PresentationNewSlideEventHandler(this.HandlePresentationNewSlide); this.ConfigurePresentationModeBar(); this.ConfigureShapeModeBar(); foreach (PowerPoint.Presentation presentation in this.myPPT.App.Presentations) this.RebuildCache(presentation); }
/* * Adds the buttons and the Sally sub menu to the context menu */ private void DefineShortcutMenu() { Office.MsoControlType menuItem = Office.MsoControlType.msoControlButton; cellbar = Application.CommandBars["Cell"]; lookupButton = (Office.CommandBarButton)cellbar.FindControl(menuItem, 0, "AlexRightClickMenu", missing, missing); if (lookupButton == null) { // first time so add the button lookupButton = (Office.CommandBarButton)cellbar.Controls.Add(menuItem, missing, missing, 1, true); lookupButton.Caption = "Sally Frame"; lookupButton.BeginGroup = true; lookupButton.Tag = "1"; lookupButton.Visible = false; } //Office.MsoControlType sub = Office.MsoControlType.msoControlPopup; //subMenu = (Office.CommandBarPopup)cellbar.Controls.Add(sub, missing, missing, 2, true); //subMenu.Caption = "Sally Options"; //subMenu.Tag = "2"; //subMenu.Visible = false; //projectMode = (Office.CommandBarButton)subMenu.Controls.Add(menuItem, missing, missing, 1, true); //projectMode.Style = Office.MsoButtonStyle.msoButtonCaption; //projectMode.Caption = "Project Mode"; //projectMode.Tag = "1"; //saveMap = (Office.CommandBarButton)subMenu.Controls.Add(menuItem, missing, missing, 2, true); //saveMap.Style = Office.MsoButtonStyle.msoButtonCaption; //saveMap.Caption = "Save semantic map"; //saveMap.Tag = "2"; }
private void AddToolbar() { if (newToolBar == null) { Office.CommandBars cmdBars = this.Application.ActiveExplorer().CommandBars; newToolBar = cmdBars.Add("NewToolBar", Office.MsoBarPosition.msoBarTop, false, true); } try { Office.CommandBarButton button_1 = (Office.CommandBarButton)newToolBar.Controls .Add(1, missing, missing, missing, missing); button_1.Style = Office .MsoButtonStyle.msoButtonIconAndCaption; button_1.Caption = "Close SalesLogix Task Pane"; button_1.Tag = "show"; button_1.FaceId = 0005; if (this.firstButton == null) { this.firstButton = button_1; firstButton.Click += new Office. _CommandBarButtonEvents_ClickEventHandler (ButtonClick); } newToolBar.Visible = true; } catch (Exception ex) { MessageBox.Show(ex.Message); } }