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.Effect = 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();
}
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…