我还没有看到这个问题的可行解决方案。
我有一个启动 Outlook 撰写窗口的外部应用程序,我想确保它始终在前面弹出。并非总是如此。例如,如果我按 Tab 键切换到 Outlook,然后返回应用程序并启动任务,它只会在底部闪烁。
我已经尝试了 getinspector.Active() 等的一些建议,但没有任何效果。
一些示例代码:
String address = "someone@example.com";
Outlook.Application oApp = new Outlook.Application();
Outlook._MailItem oMailItem = (Outlook._MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem);
oMailItem.To = address
oMailItem.Body = "example";
oMailItem.Display(true); //true = modal which I need for this task, have tried without also.
Run Code Online (Sandbox Code Playgroud)
这是您需要的工作代码。将窗口带到前台的缺少成分实际上是“inspector.Activate()”,并且您必须在“mailItem.Display”之后调用它。
var outlookApp = new Microsoft.Office.Interop.Outlook.Application();
MailItem mailItem = outlookApp.CreateItem(OlItemType.olMailItem);
mailItem.Subject = "subject";
var inspector = mailItem.GetInspector; // Force the "HTMLBody" property to be populated with any email signature, so that we can append it to our content.
mailItem.HTMLBody = "My message" + mailItem.HTMLBody;
mailItem.Attachments.Add("attachment.dat", OlAttachmentType.olByValue);
mailItem.Display(false); // Display the email
inspector.Activate(); // Bring the editor to the foreground.
Run Code Online (Sandbox Code Playgroud)