outlook添加CommandBar和CommandBarButton

来源:互联网 发布:成品油批发价年度数据 编辑:程序博客网 时间:2024/06/10 06:38

如果您不明白 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;         }      }
原创粉丝点击