Visual Studio Developer Center > Visual Studio Forums > Visual Studio Tools for Office > How to hide the default context menu and display a custom context menu in Excel 2007?

Answered How to hide the default context menu and display a custom context menu in Excel 2007?

  • Thursday, November 06, 2008 7:31 AM
     
     
    Hi All,

    I am trying to show a custom menu when the user right mouse click on a cell. I have added some menu items but my menu items are appearing along with the default Right mouse menu's. How can I show my custom menu items only when the user click on a cell.

    My project is a Excel workbook project and I developed the application using c#.

    Please help
    kris

Answers

  • Tuesday, November 11, 2008 9:34 AM
    Moderator
     
     Answered Has Code
     Hi ,
    Yes, it's possible.

    Please try the following code:

     Office.CommandBarButton cbtn;  
     
            private void ThisWorkbook_Startup(object sender, System.EventArgs e)  
            {  
                foreach (Office.CommandBarControl btn in this.Application.CommandBars["Cell"].Controls)  
                {  
                    btn.Visible = false;  
                }  
     
     
                cbtn = this.Application.CommandBars["Cell"].Controls.Add(Office.MsoControlType.msoControlButton, missing, missing, missing, trueas Office.CommandBarButton;  
     
                cbtn.Caption = "dsdf";  
                cbtn.Click += new Microsoft.Office.Core._CommandBarButtonEvents_ClickEventHandler(cbtn_Click);  
            }  
     
            void cbtn_Click(Microsoft.Office.Core.CommandBarButton Ctrl, ref bool CancelDefault)  
            {  
                MessageBox.Show("");  
            } 

    Thanks
    • Marked As Answer by Tim LiModerator Thursday, November 13, 2008 2:20 AM
    •