outlook添加CommandBar和CommandBarButton

如果您不明白 CommandBar和CommandBarButton,建议您看看office编程。看一些概念性的东西。虽然是vba的,但是照猫画虎还是可以的。

添加CommandBar

/// 
      /// 添加bar(小荷扬扬原创)
      /// 
      public class Addbar
      {
          CommandBar bar;
          public Addbar(CommandBars bars, string caption)
          {
              //返回具有指定caption的工具栏,如果不存在添加
              try
              {
                  bar = bars[caption];
                  bar.Visible = true;
              }
              catch (System.Exception)
              {
                  bar = (CommandBar)bars.Add(caption, MsoBarPosition.msoBarTop, false, true);//Temporary参数指出Outlook应该在Outlook会话间保持命令栏
                  bar.Protection = MsoBarProtection.msoBarNoResize | MsoBarProtection.msoBarNoChangeDock;
                  bar.Visible = true;
              }
          }
          public CommandBar getBar()
          {
              return bar;
          }
      }

添加CommandBarButton

/// 
      /// 添加按钮的基类(小荷扬扬原创)
      /// 
     public     class Btn 
      {
         protected     CommandBarButton MyButton;//要添加的按钮
         protected Outlook.Application applicationObject;
         public Btn()
         { }
         /// 
         /// 工具栏添加按钮
         /// 
         /// 要添加按钮的工具栏
         /// 按钮的标题
         /// outlook应用程序
         public Btn(CommandBar commandbar, string caption, Outlook.Application applicationObject)
         {
             try
             {
                 if (applicationObject!=null )
                 {
                     this.applicationObject = applicationObject;
                 }
                 MyButton = (CommandBarButton)commandbar.Controls[caption];
             }
             catch (System.Exception)
             {
                 object omissing = System.Reflection.Missing.Value;
                 MyButton = (CommandBarButton)commandbar.Controls.Add(MsoControlType.msoControlButton, omissing, omissing, omissing, omissing);
                 MyButton.Caption = caption;
                 MyButton.Style = MsoButtonStyle.msoButtonCaption;//显示按钮外观和标题文本的msoButtonIconAndCaption
                 MyButton.Visible = true;
                 MyButton.Click += new _CommandBarButtonEvents_ClickEventHandler(MyButton_Click);
             }
         }
         /// 
         /// 菜单栏添加按钮
         /// 
         /// 要添加按钮的菜单栏
         /// 标题
         /// outlook应用程序
         public Btn(CommandBarPopup barPopup, string caption, Outlook.Application applicationObject)
         {
             try
             {
                 if (applicationObject!=null )
                 {
                     this.applicationObject = applicationObject;
                 }
                 MyButton = (CommandBarButton)barPopup.Controls[caption];
             }
             catch (System.Exception)
             {
                 object omissing = System.Reflection.Missing.Value;
                 MyButton = (CommandBarButton)barPopup.Controls.Add(MsoControlType.msoControlButton, omissing, omissing, omissing, omissing);
                 MyButton.Caption = caption;
                 MyButton.Style = MsoButtonStyle.msoButtonCaption;
                 MyButton.Visible = true;
                 MyButton.Click += new _CommandBarButtonEvents_ClickEventHandler(MyButton_Click);
             }
         }
         /// 
         /// 按钮的单击事件
         /// 
         /// 按钮
         /// 时间是否取消
         public virtual void MyButton_Click(CommandBarButton Ctrl, ref bool CancelDefault)
         {

         }
         /// 
         /// 返回添加的按钮
         /// 
         /// 
  
  返回添加的按钮
         public CommandBarButton getButton()
         {
             return MyButton;
         }
      }
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值