首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Outlook加载项、RibbonType Microsoft.Outlook.Explorer和Microsoft.Outlook.Mail.Read

Outlook加载项、RibbonType Microsoft.Outlook.Explorer和Microsoft.Outlook.Mail.Read
EN

Stack Overflow用户
提问于 2013-04-18 21:57:35
回答 2查看 6K关注 0票数 6

我有一个Outlook2010外接程序编码在.NET 4.0/VS.NET2010,C#。该加载项扩展了功能区=>,它将具有4个RibbonButtons的RibbonTab添加到(RibbonType属性设置为) Microsoft.Outlook.ExplorerMicrosoft.Outlook.Mail.Read

现在,如果用户单击其中一个RibbonButtons,我如何确定用户是否单击了添加到Microsoft.Outlook.Explorer OR Microsoft.Outlook.Mail.Read中的按钮

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2013-04-19 00:23:07

一种选择是创建(2)个具有共享功能库的功能区。调用共享库时,可以传递单击的功能区操作的上下文。

不过,更好的选择是检查应用程序的ActiveWindow属性,以通过ThisAddin.Application.ActiveWindow()确定用户所处的上下文。

代码语言:javascript
复制
 var windowType = Globals.ThisAddin.Application.ActiveWindow();
 if (windowType is Outlook.Explorer)
 {
     Outlook.Explorer exp = type as Outlook.Explorer;
     // you have an explorer context
 }
 else if (windowType is Outlook.Inspector)
 {
     Outlook.Inspector exp = type as Outlook.Inspector;
     // you have an inspector context
 }
票数 6
EN

Stack Overflow用户

发布于 2013-04-22 17:23:47

SilverNinja的提议给我指明了一个方向。最后,我的代码是:

代码语言:javascript
复制
                // get active Window
            object activeWindow = Globals.ThisAddIn.Application.ActiveWindow();
            if (activeWindow is Microsoft.Office.Interop.Outlook.Explorer)
            {
                // its an explorer window
                Outlook.Explorer explorer = Globals.ThisAddIn.Application.ActiveExplorer();
                Outlook.Selection selection = explorer.Selection;
                for (int i = 0; i < selection.Count; i++)
                {
                    if (selection[i + 1] is Outlook.MailItem)
                    {
                        Outlook.MailItem mailItem = selection[i + 1] as Outlook.MailItem;
                        CreateFormOrForm(mailItem);
                    }
                    else
                    {
                        Logging.Logging.Log.Debug("One or more of the selected items are not of type mail message..!");
                        System.Windows.Forms.MessageBox.Show("One or more of the selected items are not of type mail message..");
                    }
                }
            }
            if (activeWindow is Microsoft.Office.Interop.Outlook.Inspector)
            {
                // its an inspector window
                Outlook.Inspector inspector = Globals.ThisAddIn.Application.ActiveInspector();
                Outlook.MailItem mailItem = inspector.CurrentItem as Outlook.MailItem;
                CreateFormOrForm(mailItem);
            }

也许这对其他人有帮助。

票数 8
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/16084995

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档