C# VSTO给Excel添加右键菜单并添加点击的click事件

Excel.Application app;
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
    app = Globals.ThisAddIn.Application;
    Office.CommandBars bars = app.CommandBars;            
    Office.CommandBar bar = bars["cell"];  //获取右键菜单项
    bar.Reset();
    Office.CommandBarControls controls = bar.Controls;
    Office.CommandBarButton newControl =(Office.CommandBarButton)controls.Add(Office.MsoControlType.msoControlButton, missing, missing, missing, true);
    newControl.Caption = "My test";
    newControl.Click += NewControl_Click;
}

private void NewControl_Click(Office.CommandBarButton Ctrl, ref bool CancelDefault)
{
    System.Windows.Forms.MessageBox.Show("Test");
}

 

C# VSTO给Excel添加右键菜单并添加点击的click事件

上一篇:在WPF使用MVVM的方式关闭窗口


下一篇:85道 Vue 面试题,内含详细讲解(涵盖入门到精通,自测 Vue 掌握程度)