예제 #1
0
        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);
        }
예제 #2
0
        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;
        }
예제 #3
0
        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);
        }
예제 #4
0
        private void ThisAddIn_Startup(object sender, System.EventArgs e)
        {
            myUserControl1   = new TaskPaneControl();
            myCustomTaskPane = this.CustomTaskPanes.Add(myUserControl1, "Business Plan Writer");
            myCustomTaskPane.VisibleChanged += new EventHandler(myCustomTaskPane_VisibleChanged);


            Office.CommandBar       cellbar = this.Application.CommandBars["Cell"];
            Office.CommandBarButton 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    = "Check Selection";
                button.BeginGroup = true;
                button.Tag        = "MYRIGHTCLICKMENU";
                button.Click     += new Office._CommandBarButtonEvents_ClickEventHandler(MyButton_Click);
            }
        }
예제 #5
0
        private void DisplayMenuOption(Office.CommandBar commandBar, Outlook.MAPIFolder folder)
        {
            try
            {
                var READOUT_BUTTON_ID = "READOUT_BUTTON_ID";
                if (commandBar.FindControl(Tag: READOUT_BUTTON_ID) != null)
                {
#if DEBUG
                    Util.AppLogger.WriteLine("Already exists");
#endif
                    return;
                }

                //var btnInitReadOut = (Office.CommandBarButton)commandBar.Controls.Add(Type: Office.MsoControlType.msoControlButton);
                //btnInitReadOut.Tag = READOUT_BUTTON_ID;
                //                btnInitReadOut.Caption = "Reinitiali&ze ReadOut Key Hook";
                //btnInitReadOut.Click += new Microsoft.Office.Core._CommandBarButtonEvents_ClickEventHandler(btnInitReadOut_Click);
                var btnReadOut = (Office.CommandBarButton)commandBar.Controls.Add(Office.MsoControlType.msoControlButton, missing, missing, missing, missing);
                btnReadOut.Tag     = READOUT_BUTTON_ID;
                btnReadOut.Caption = "Read&Out";
                btnReadOut.Click  += new Microsoft.Office.Core._CommandBarButtonEvents_ClickEventHandler(btnReadOut_Click);
                CurrentFolder      = folder;
                if (folder.Items.Count <= 0)
                {
                    btnReadOut.Enabled = false;
                }

#if DEBUG
                var btnDump = (Office.CommandBarButton)commandBar.Controls.Add(Type: Office.MsoControlType.msoControlButton);
                btnDump.Caption = "Dump Key Hook";
                btnDump.Click  += new Microsoft.Office.Core._CommandBarButtonEvents_ClickEventHandler(
                    (Office.CommandBarButton Ctrl, ref bool CancelDefault) => _panelManager.WriteState()
                    );
                #endif
            }
            catch (Exception ex)
            {
                ExceptionHandler.Catch(ex);
            }
        }
예제 #6
0
        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;
        }
예제 #7
0
파일: ThisAddIn.cs 프로젝트: imysecy/SPLINK
        /// <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)
            {

            }
        }
        private void AddToolbar()
        {
            string barName            = Properties.Resources.OrdersToolbar;
            string weeklyCaption      = Properties.Resources.WeeklyMenu;
            string unscheduledCaption = Properties.Resources.UnscheduledMenu;

            // Toolbars are unique for the whole application.
            // In case there are two workbooks running this code,
            // the second workbook should check first if the
            // toolbar is already there.
            // If it is not, it has to be created.
            // In any case, a handler must be added.
            Office.CommandBar commandBar = null;

            Office.CommandBarButton weeklyButton;
            Office.CommandBarButton unscheduledButton;

            for (int i = 1; i <= ThisApplication.CommandBars.Count; ++i)
            {
                if (ThisApplication.CommandBars[i].Name == barName)
                {
                    commandBar = ThisApplication.CommandBars[i];
                    break;
                }
            }

            if (commandBar == null)
            {
                commandBar = this.Application.CommandBars.Add(barName, Office.MsoBarPosition.msoBarTop, missing, true);
            }


            if (commandBar.FindControl(missing, missing, weeklyCaption, missing, false) == null)
            {
                weeklyButton = (Office.CommandBarButton)commandBar.Controls.Add(Office.MsoControlType.msoControlButton, missing, missing, missing, missing);

                weeklyButton.Caption = weeklyCaption;

                weeklyButton.Picture = ExcelHelpers.Convert(toolBarImages.Images["CreateWeeklyOrder"]);
                weeklyButton.Mask    = ExcelHelpers.Convert(toolBarImages.Images["CreateWeeklyOrderMask"]);
                weeklyButton.Tag     = weeklyCaption;
            }
            else
            {
                weeklyButton = (Office.CommandBarButton)commandBar.Controls[weeklyCaption];
            }

            if (commandBar.FindControl(missing, missing, unscheduledCaption, missing, false) == null)
            {
                unscheduledButton = (Office.CommandBarButton)commandBar.Controls.Add(Office.MsoControlType.msoControlButton, missing, missing, missing, missing);

                unscheduledButton.Caption = unscheduledCaption;

                unscheduledButton.Picture = ExcelHelpers.Convert(this.toolBarImages.Images["CreateUnscheduledOrder"]);
                unscheduledButton.Mask    = ExcelHelpers.Convert(this.toolBarImages.Images["CreateUnscheduledOrderMask"]);
                unscheduledButton.Tag     = unscheduledCaption;
            }
            else
            {
                unscheduledButton = (Office.CommandBarButton)commandBar.Controls[unscheduledCaption];
            }

            commandBar.Visible = true;

            this.weeklyToolbarButton      = weeklyButton;
            this.unscheduledToolbarButton = unscheduledButton;

            this.toolBar = commandBar;
        }
예제 #9
0
        /*
         * 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";
        }
예제 #10
0
        private void AddToolbar()
        {
            string barName            = Properties.Resources.OrdersToolbar;
            string weeklyCaption      = Properties.Resources.WeeklyMenu;
            string unscheduledCaption = Properties.Resources.UnscheduledMenu;

            // 工具栏对于整个应用程序是唯一的。
            // 如果有两个工作簿运行此代码,
            // 第二个工作簿应先检查工具栏
            // 是否已存在。
            // 如果不存在,则必须创建。
            // 在任何情况下,都必须添加一个处理程序。
            Office.CommandBar commandBar = null;

            Office.CommandBarButton weeklyButton;
            Office.CommandBarButton unscheduledButton;

            for (int i = 1; i <= ThisApplication.CommandBars.Count; ++i)
            {
                if (ThisApplication.CommandBars[i].Name == barName)
                {
                    commandBar = ThisApplication.CommandBars[i];
                    break;
                }
            }

            if (commandBar == null)
            {
                commandBar = this.Application.CommandBars.Add(barName, Office.MsoBarPosition.msoBarTop, missing, true);
            }


            if (commandBar.FindControl(missing, missing, weeklyCaption, missing, false) == null)
            {
                weeklyButton = (Office.CommandBarButton)commandBar.Controls.Add(Office.MsoControlType.msoControlButton, missing, missing, missing, missing);

                weeklyButton.Caption = weeklyCaption;

                weeklyButton.Picture = ExcelHelpers.Convert(toolBarImages.Images["CreateWeeklyOrder"]);
                weeklyButton.Mask    = ExcelHelpers.Convert(toolBarImages.Images["CreateWeeklyOrderMask"]);
                weeklyButton.Tag     = weeklyCaption;
            }
            else
            {
                weeklyButton = (Office.CommandBarButton)commandBar.Controls[weeklyCaption];
            }

            if (commandBar.FindControl(missing, missing, unscheduledCaption, missing, false) == null)
            {
                unscheduledButton = (Office.CommandBarButton)commandBar.Controls.Add(Office.MsoControlType.msoControlButton, missing, missing, missing, missing);

                unscheduledButton.Caption = unscheduledCaption;

                unscheduledButton.Picture = ExcelHelpers.Convert(this.toolBarImages.Images["CreateUnscheduledOrder"]);
                unscheduledButton.Mask    = ExcelHelpers.Convert(this.toolBarImages.Images["CreateUnscheduledOrderMask"]);
                unscheduledButton.Tag     = unscheduledCaption;
            }
            else
            {
                unscheduledButton = (Office.CommandBarButton)commandBar.Controls[unscheduledCaption];
            }

            commandBar.Visible = true;

            this.weeklyToolbarButton      = weeklyButton;
            this.unscheduledToolbarButton = unscheduledButton;

            this.toolBar = commandBar;
        }