Visual Studio Developer Center > Visual Studio Forums > Visual Studio Tools for Office > Add a new menue item to Right click menu(VSTO SE)

Answered Add a new menue item to Right click menu(VSTO SE)

  • Friday, March 30, 2007 3:58 AM
     
     
    Dear Sir,

    I am developing Word 2007 Add-in. and using VSTO SE.

    I want to add a new menue item to Right click menu when user right click on a selected letter.
    That is say user click on a letter selected i wont to show a new menu item just like what happen when you right lick to correct the spellings of a incorrect word you see sugessions in the Right click menu.

    Please let me know what are the techniques can be used to tackel these situation. Also if you have any code samples post it. It would be helpful.

    Thanks
    Tharindu

Answers

  • Friday, March 30, 2007 2:55 PM
     
     Answered

     

    hi Tharindu !!

     

    i hope that this sample could help you :

     

    internal void Application_WindowBeforeRightClick(Microsoft.Office.Interop.Word.Selection Sel, ref bool Cancel)

    {

           AddContextMenu();

    }

     

    internal void AddContextMenu()

    {

        Office.CommandBar _ContextMenu = this.Application.CommandBars.Add("ContextMenu", Office.MsoBarPosition.msoBarPopup, missing, true);

     

        if (_ContextMenu != null)

        {

            Office.CommandBarButton cb = (Office.CommandBarButton)_ContextMenu.Controls.Add(Office.MsoControlType.msoControlButton, missing, missing, missing, true);

     

            if (cb != null)

            {

                cb.Caption = Caption;

                cb.BeginGroup = BeginGroup;

                cb.Tag = Tag;

                cb.FaceId = FaceId;

                 cb.Click += new Microsoft.Office.Core._CommandBarButtonEvents_ClickEventHandler(_Button_Click);

            }

          

           _ContextMenu.ShowPopup(missing, missing);

        

        }

    }

     

    Best regards !!!

All Replies

  • Friday, March 30, 2007 2:55 PM
     
     Answered

     

    hi Tharindu !!

     

    i hope that this sample could help you :

     

    internal void Application_WindowBeforeRightClick(Microsoft.Office.Interop.Word.Selection Sel, ref bool Cancel)

    {

           AddContextMenu();

    }

     

    internal void AddContextMenu()

    {

        Office.CommandBar _ContextMenu = this.Application.CommandBars.Add("ContextMenu", Office.MsoBarPosition.msoBarPopup, missing, true);

     

        if (_ContextMenu != null)

        {

            Office.CommandBarButton cb = (Office.CommandBarButton)_ContextMenu.Controls.Add(Office.MsoControlType.msoControlButton, missing, missing, missing, true);

     

            if (cb != null)

            {

                cb.Caption = Caption;

                cb.BeginGroup = BeginGroup;

                cb.Tag = Tag;

                cb.FaceId = FaceId;

                 cb.Click += new Microsoft.Office.Core._CommandBarButtonEvents_ClickEventHandler(_Button_Click);

            }

          

           _ContextMenu.ShowPopup(missing, missing);

        

        }

    }

     

    Best regards !!!

  • Thursday, April 05, 2007 3:40 AM
     
     
    Dear Sir,

    I added this code to the "ThisAddIn"  class. but when i right click i didnt get the output. When i debug the Application_WindowBeforeRightClick event did not fire.

    Please help me where should I put this code and whats the procedure i should follow in order to get tis code work.

     Thanks for the help .

    Regards
    Tharindu
  • Thursday, April 05, 2007 2:17 PM
     
     

    Hi !!

     

    You must declare in the Startup event of the add-in for example the code below

     

    this.Application.WindowBeforeDoubleClick += new Microsoft.Office.Interop.Word.ApplicationEvents4_WindowBeforeDoubleClickEventHandler(Application_WindowBeforeDoubleClick);

     

     

    Best regards !!!

  • Saturday, April 07, 2007 7:00 AM
     
     
    Dear Sir,

    Thanks it worked all right. But when i right click still the defult menu aprears after my menu. its disturbing to the user. Can we either include my menu as a sun menu in defult right clikck menu or can we desable right click menu appring.

    Regards,
    Tharindu
  • Tuesday, April 10, 2007 4:17 PM
     
     

    Hi !!

     

    internal void Application_WindowBeforeRightClick(Microsoft.Office.Interop.Word.Selection Sel, ref bool Cancel)

    {

        Cancel = true; // Disable the office context menu

       

        AddContextMenu();

    }

     

    Regards

    Franck