Chr*_*utt 4 c# vsto outlook-addin outlook-2010
我有一个在.NET 4.0/VS.NET 2010 C#中编写的Outlook 2010加载项.加载项扩展了Ribbon =>它添加了一个RibbonTab带有4个RibbonButtons(RibbonType属性设置为)Microsoft.Outlook.Explorer和Microsoft.Outlook.Mail.Read.
现在,如果用户单击其中一个RibbonButtons,我如何确定用户是否单击了添加到Microsoft.Outlook.ExplorerOR 的按钮Microsoft.Outlook.Mail.Read?
一种选择是使用共享功能库创建 (2) 个功能区。当您调用共享库时 - 您可以传递单击功能区操作的上下文。
更好的选择是检查ActiveWindow应用程序的属性,以确定用户在通过的上下文ThisAddin.Application.ActiveWindow()。
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
}
Run Code Online (Sandbox Code Playgroud)
SilverNinja的提议指出了我的方向..最后我的代码是:
// 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);
}
Run Code Online (Sandbox Code Playgroud)
也许这对其他人有帮助......