C#将Outlook窗口置于最前面 [英] c# bring outlook window to front

查看:207
本文介绍了C#将Outlook窗口置于最前面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我还没有找到解决此问题的可行解决方案.

I have not yet been able to see a workable solution for this problem.

我有一个外部应用程序,它会启动一个Outlook撰写窗口,并且我想确保它始终在前面弹出.并非一直如此.例如.如果我使用Tab键查看Outlook,然后返回到应用程序并启动任务,它将在底部闪烁.

I have an external application that launches an outlook compose window, and I want to make sure it always pop up in front. It does not all the time. E.g. if I tab to Outlook and then back to the application and launch the task, it will just blink in the bottom.

我用getinspector.Active()等尝试了一些建议,但是没有任何效果.

I've tried several suggestions with getinspector.Active() etc. but nothing works.

一些示例代码:

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.

类似的线程,但是带有我不知道的Delphi代码如何翻译成c#

推荐答案

这是您需要的工作代码.实际上,将窗口带到前台所缺少的成分是"inspector.Activate()",您必须在 之后将其称为"mailItem.Display".

Here's the working code you need. The missing ingredient to bring the window to the foreground is in fact "inspector.Activate()", and you must call this after "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.

这篇关于C#将Outlook窗口置于最前面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆