使用VS2008进行VSTO-Addin实战开发-创建自己的工具栏(二)

http://www.cnblogs.com/jetxia/archive/2007/09/29/910341.html

 

Posted on 2007-09-29 10:05   笑缘  阅读(370)   评论(2)    编辑   收藏   网摘  所属分类:   02 C# WINDOWS  
操作系统:Windows Vista
开发环境:Visual Studio 2008 Beta2
运行环境:Microsoft office 2007(Outlook)

代码主要示例了如何创建工具栏,以及在工具栏上添加按钮和按钮的Click事件。


  private   void  ThisAddIn_Startup( object  sender, System.EventArgs e)
        
{
            
this.AddBar();
        }


        
private   void  ThisAddIn_Shutdown( object  sender, System.EventArgs e)
        
{
        }


        
private   void  AddBar()
        
{
            
//创建一个TopBar
            Office.CommandBar barTopCommand = this.Application.ActiveExplorer().CommandBars.Add("My Top Command", Office.MsoBarPosition.msoBarTop,falsetrue);

            
//在创建的barTopCommand上创建一个CommandBarButton
            Office.CommandBarButton button1 = barTopCommand.Controls.Add(Office.MsoControlType.msoControlButton, Type.Missing, Type.Missing, Type.Missing, trueas Office.CommandBarButton;

            button1.Caption 
= "My Button";
            button1.Visible 
= true;

            
//添加button1的Click事件
            button1.Click += new Microsoft.Office.Core._CommandBarButtonEvents_ClickEventHandler(button1_Click);

        }


        
void  button1_Click(Microsoft.Office.Core.CommandBarButton Ctrl,  ref   bool  CancelDefault)
        
{
            MessageBox.Show(
"Hello button1");
        }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值