新的电子邮件锁定Outlook,强制电子邮件窗口为topMost

ika*_*eat 5 c# outlook topmost

我使用以下代码从DataGridView读取电子邮件地址,然后创建Outlook电子邮件.除了将新电子邮件设置为topMost和/或打开为对话框窗口之外,这非常有效,这意味着在新电子邮件窗口打开时我无法在Outlook中单击或执行任何其他操作.如果我打开新电子邮件并尝试在收件箱中搜索或查找某些内容,则会出现问题.在我关闭或发送电子邮件之前,我的申请也不会回复(被锁定).

有没有办法创建一个新的电子邮件,仍然允许常规功能?如果我从Outlook本身单击新的电子邮件按钮,我可以根据需要打开这些按钮,使用搜索等.

this.TopMost = false行是隐藏我的WinForms应用程序并在前面显示新的电子邮件窗口.

try
{

      string emailString = resultsGrid[resultsGrid.Columns["Email"].Index, resultsGrid.SelectedCells[resultsGrid.Columns["Email"].Index].RowIndex].Value.ToString();

    if(emailString.Contains("mailto:"))
    {
        emailString = emailString.Replace("mailto:", "");
    }

    this.TopMost = false;

    // Create the Outlook application by using inline initialization.
    Outlook.Application oApp = new Outlook.Application();

    //Create the new message by using the simplest approach.
    Outlook.MailItem oMsg = (Outlook.MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem);
    oMsg.Subject = "";
    oMsg.To = emailString;
    oMsg.Body = "";
    oMsg.Display(true);


    oMsg = null;
    oApp = null;
}
catch (Exception ex)
{
    MessageBox.Show(string.Format("An error occurred: {0}", ex.Message));
}
Run Code Online (Sandbox Code Playgroud)

同样奇怪的是,如果我在电子邮件中写一些东西并关闭它,我可以保存它.如果我这样做,当我打开电子邮件备份时,它会返回到锁定状态.我开始认为这与电子邮件的创建方式有关,因此一些设置或属性正在应用并随之保存.

Dou*_*las 9

尝试替换此行:

oMsg.Display(true);
Run Code Online (Sandbox Code Playgroud)

...有:

oMsg.Display(false);
Run Code Online (Sandbox Code Playgroud)

根据MailItem.Display文档,参数的名称是Modal,并且应该指定为:

True使窗口模态.默认值为False.