asp.net c# Design Pattern WebService Windows Report Control Mobile Symbin Windows Phone 7 Visual Studio 2011

使用VS2008进行VSTO-Addin实战开发-创建自己的菜单(一)

Posted on 2007-09-28 17:36  笑缘  阅读(3092)  评论(4编辑  收藏  举报
操作系统:Windows Vista
开发环境:Visual Studio 2008 Beta2
运行环境:Microsoft office 2007(Outlook)

初次使用VSTO,代码主要示例了如何创建菜单,以及响应菜单的Click事件来创建一个MailItem。

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


        
private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
        
{
           
// MessageBox.Show("Stoped");
        }



        
private void AddMenu()
        
{
            
//获取Outlook的MenuBar
            Office.CommandBar bar = this.Application.ActiveExplorer().CommandBars.ActiveMenuBar;
            
//创建顶级菜单
            Office.CommandBarControl menuTop = bar.Controls.Add(Office.MsoControlType.msoControlPopup, Type.Missing, Type.Missing, bar.Controls.Count, true);
            menuTop.Caption 
= "我的菜单";

            Office.CommandBarPopup commandBarPopupTmp
= menuTop.Control as Office.CommandBarPopup;
           
            Office.CommandBarControl menuGroup 
= null;
            Office.CommandBarControl menuCreateMail 
= null;

            
if (commandBarPopupTmp.Controls.Count == 0)
            
{
                menuGroup 
= commandBarPopupTmp.Controls.Add(Office.MsoControlType.msoControlPopup, Type.Missing, Type.Missing, Type.Missing, true);
            }

            
else
            
{
                menuGroup 
= commandBarPopupTmp.Controls.Add(Office.MsoControlType.msoControlPopup, Type.Missing, Type.Missing, commandBarPopupTmp.Controls.Count, true);
            }


            menuCreateMail 
= commandBarPopupTmp.Controls.Add(Office.MsoControlType.msoControlButton, Type.Missing, Type.Missing, 1true);

            menuGroup.Caption 
= "菜单组";

            menuCreateMail.Caption 
= "创建我的邮件";

            Office.CommandBarButton buttonMenu 
= menuCreateMail as Office.CommandBarButton;
            buttonMenu.Click 
+= new Microsoft.Office.Core._CommandBarButtonEvents_ClickEventHandler(buttonMenu_Click);
        }


        
void buttonMenu_Click(Microsoft.Office.Core.CommandBarButton Ctrl, ref bool CancelDefault)
        
{
            Outlook.MailItem mail 
= this.Application.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem) as Outlook.MailItem;
            mail.To 
= "jetxia@126.com";
            mail.Subject 
= "Test mail";
            mail.Body 
= "Hi, this is a test.";
           
            mail.Display(Type.Missing);

            
//mail.Send();
        }

示例代码下载
/Files/jetxia/VSTO/VSTO_MyMenu.zip

Copyright © 2024 笑缘
Powered by .NET 8.0 on Kubernetes

asp.net c# Design Pattern WebService Windows Report Control Mobile Windows Phone Visual Studio
asp.net c# Design Pattern WebService Windows Report Control Mobile