从Outlook电子邮件获取体[拖放] [英] Get body from Outlook email [Drag’n’Drop]
问题描述
我与WPF工作,我试图做一个拖放文本框。
在这个文本我想这是我从Outlook拖动一个电子邮件的正文。
在code ++工程,但我想我需要一些东西来重置ActiveExplorer原因,现在只显示最后一个NEW的电子邮件,我拖入文本框。
的 示例:的
将电子邮件1 - >文本框 - 显示电子邮件1
将电子邮件2 - >文本框 - 显示电子邮件2
将电子邮件1 - >文本框 - 显示电子邮件2和电子邮件1将不会显示,因为它已经在ActiveExplorer存在,它会显示邮件2
结果
希望我的问题是有点清楚你..
在此先感谢!
XAML code:
<文本框
NAME =myTextbox
的AllowDrop =真
previewDragEnter =email_DragEnter
previewDrop =email_Drop/>
XAML code背后:
私人无效email_DragEnter(对象发件人,DragEventArgs E)
{
e.Effects = DragDropEffects.Copy;
} 私人无效email_Drop(对象发件人,DragEventArgs E)
{
Outlook.ApplicationClass oApp =新Outlook.ApplicationClass();
Outlook.Explorer oExplorer = oApp.ActiveExplorer();
Outlook.Selection oSelection = oExplorer.Selection; 的foreach(在oSelection对象项)
{
Outlook.MailItem MI =(Outlook.MailItem)项目;
myTextbox.Text = mi.Body.ToString();
}
}
我搬到 oApp的声明
出DragDrop事件,如下,它按预期工作。
无效启动()
{
_Outlook =新Outlook.Application();
}Outlook.Application _Outlook = NULL;私人无效Form1_DragEnter(对象发件人,DragEventArgs E)
{
e.Effect = DragDropEffects.Copy;
}私人无效Form1_DragDrop(对象发件人,DragEventArgs E)
{
richTextBox1.Text =;
Outlook.Explorer oExplorer = _Outlook.ActiveExplorer();
Outlook.Selection oSelection = oExplorer.Selection; 的foreach(在oSelection对象项)
{
Outlook.MailItem MI =(Outlook.MailItem)项目;
richTextBox1.AppendText(mi.Body.ToString()+\\ n ----------------------------------- ----- \\ n);
}
}
-------- --------编辑
或者是有可能你显示,因为这个循环的唯一的最后一个项目?
的foreach(在oSelection对象项)
{
Outlook.MailItem MI =(Outlook.MailItem)项目;
myTextbox.Text = mi.Body.ToString(); //< ---就在上项目的文本
}
I’m working with WPF and I’m trying to make a drag’n’drop textbox.
In this textbox I want to get the body of an email which I drag from outlook.
The code works but I think I need something to "reset" the ActiveExplorer cause now it only shows the last "NEW" email which I drag into the textbox.
Example:
Drag email 1 -> Textbox - Shows email 1
Drag email 2 -> Textbox - Shows email 2
Drag email 1 -> Textbox - Shows email 2 and email 1 will not be displayed because it already exists in the ActiveExplorer and it will show email 2.
Hope my question is a bit clear to you..
Thanks in advance!
XAML code:
<TextBox
Name="myTextbox"
AllowDrop="True"
PreviewDragEnter="email_DragEnter"
PreviewDrop="email_Drop" />
XAML code behind:
private void email_DragEnter(object sender, DragEventArgs e)
{
e.Effects = DragDropEffects.Copy;
}
private void email_Drop(object sender, DragEventArgs e)
{
Outlook.ApplicationClass oApp = new Outlook.ApplicationClass();
Outlook.Explorer oExplorer = oApp.ActiveExplorer();
Outlook.Selection oSelection = oExplorer.Selection;
foreach (object item in oSelection)
{
Outlook.MailItem mi = (Outlook.MailItem)item;
myTextbox.Text = mi.Body.ToString();
}
}
I moved the declaration of oApp
out of DragDrop event as below, and it works as expected.
void Startup()
{
_Outlook = new Outlook.Application();
}
Outlook.Application _Outlook = null;
private void Form1_DragEnter(object sender, DragEventArgs e)
{
e.Effect = DragDropEffects.Copy;
}
private void Form1_DragDrop(object sender, DragEventArgs e)
{
richTextBox1.Text = "";
Outlook.Explorer oExplorer = _Outlook.ActiveExplorer();
Outlook.Selection oSelection = oExplorer.Selection;
foreach (object item in oSelection)
{
Outlook.MailItem mi = (Outlook.MailItem)item;
richTextBox1.AppendText(mi.Body.ToString() + "\n----------------------------------------\n");
}
}
--------EDIT--------
OR Is it possible that you display only the last item because of this loop?
foreach (object item in oSelection)
{
Outlook.MailItem mi = (Outlook.MailItem)item;
myTextbox.Text = mi.Body.ToString(); //<--- Only last items text
}
这篇关于从Outlook电子邮件获取体[拖放]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!