我有一个Outlook2010外接程序编码在.NET 4.0/VS.NET2010,C#。该加载项扩展了功能区=>,它将具有4个RibbonButtons的RibbonTab添加到(RibbonType属性设置为) Microsoft.Outlook.Explorer和Microsoft.Outlook.Mail.Read。
现在,如果用户单击其中一个RibbonButtons,我如何确定用户是否单击了添加到Microsoft.Outlook.Explorer OR Microsoft.Outlook.Mail.Read中的按钮
发布于 2013-04-19 00:23:07
一种选择是创建(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
}发布于 2013-04-22 17:23:47
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);
}也许这对其他人有帮助。
https://stackoverflow.com/questions/16084995
复制相似问题