删除标准工具栏中的按钮,如果已经在Outlook中找到
本文关键字:Outlook 如果 标准工具栏 按钮 删除 | 更新日期: 2023-09-27 18:02:30
我在主Outlook窗口的标准工具栏中添加了一个按钮。它在我构建Outlook Project时运行。但是每当我再次构建项目时,该按钮就会在主Outlook窗口中再次复制。
我的代码:
private void AddToolbar()
{
if (cbar == null)
{
cbar = this.Application.ActiveExplorer().CommandBars["Standard"];
}
try
{
Office.CommandBarButton btn = (Office.CommandBarButton)cbar.Controls.Add(1, missing, missing, missing, missing);
btn.Caption = "button1";
btn.Tag = "button1";
if (this.firstButton == null)
{
this.firstButton = btn;
firstButton.Click += new Office._CommandBarButtonEvents_ClickEventHandler(ButtonClick);
}
}
catch (System.Exception ex)
{
MessageBox.Show(ex.Message);
}
}
如果已经找到,如何添加此按钮的删除功能?
您可能希望在创建另一个按钮之前检查firstButton
是否为null。例如:
if (this.firstButton == null)
{
Office.CommandBarButton btn = (Office.CommandBarButton)cbar.Controls.Add(1, missing, missing, missing, missing);
btn.Caption = "button1";
btn.Tag = "button1";
this.firstButton = btn;
firstButton.Click += new Office._CommandBarButtonEvents_ClickEventHandler(ButtonClick);
}