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

来源:互联网 发布:windows phone安装apk 编辑:程序博客网 时间:2024/06/06 12:26

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");
        }
原创粉丝点击