コンテキストメニューボタンが1回だけ発生します。 起動時にbtnオブジェクトが終了します。どうすれば修正できますか?コンテキストメニューボタンがExcelアドインで1回発生します
どうすれば呼び出しオブジェクトを早期に修正できますか?
public partial class ThisAddIn
{
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
PicPaste btn = new PicPaste(this.Application);}
class PicPaste
{
private Excel.Application application;
private Office.CommandBarButton picpasteMenuItem;
public PicPaste(Excel.Application app)
{
application = app;
CreatePicpasteBtn();
}
public void CreatePicpasteBtn()
{
Office.MsoControlType contextMenuItem = Office.MsoControlType.msoControlButton;
Office.CommandBar commandBarCell = application.CommandBars["Cell"];
picpasteMenuItem = commandBarCell.Controls.Add(contextMenuItem, Type.Missing, Type.Missing, 5, true)
as Office.CommandBarButton;
if (picpasteMenuItem != null)
{
picpasteMenuItem.Style = Office.MsoButtonStyle.msoButtonCaption;
picpasteMenuItem.Caption = "Вставить изображение в коммент";
picpasteMenuItem.Click += new Office._CommandBarButtonEvents_ClickEventHandler(
PicPasteMenuItemClick);
}
}
private static void PicPasteMenuItemClick(Office.CommandBarButton Ctrl, ref bool CancelDefault)
{
...some code here
}
}