I am having a problem with my WinForms-Application; I want to drag and send Outlook mail to a RichTextBox. I found many articles about the Drag & Drop function, but they all embed Mailtext in rTB (see link ). In fact, I can insert a document as .txt, .jpg, Outlook mail from the desktop ... into my program. My richTextBox automatically creates an image for the file and inserts that image into position. How:
.
After the user drags the file, the image will be created in the “Drop” position, and if the user double-clicks the image, the file will be opened.
Problem:
The program works fine, but if I try to drag and drop mail from Outlook, the program inserts the mailbox into a richTextBox and not as an image.
I saved one Mail on the desktop and try to paste this letter into my program. The following output is in my richTextBox (would be perfect):
Mailicon from the desktop to Drag & Drop:

Otherwise, I tried to drag and drop May from Outlook into my program, and the following output is given (just look at the text, not the images:
Mail from Outlook for Drag & Drop (PROBLEM !!!):

The program inserts cc / mailadress and Mailbody into rTB.
Here is the code behind: (My richTextBox is my own created richTextBox called MyRichTextBox. Download the project under: link_RICHTEXTBOX .
CODE
private void Form1DragDrop(object sender, DragEventArgs e)
{
Startup();
Microsoft.Office.Interop.Outlook.Explorer oExplorer = _Outlook.ActiveExplorer();
Microsoft.Office.Interop.Outlook.Selection oSelection = oExplorer.Selection;
foreach (object item in oSelection)
{
Microsoft.Office.Interop.Outlook.MailItem mi = (Microsoft.Office.Interop.Outlook.MailItem)item;
rTB_test.Text = mi.Body.ToString();
string mailName = "Mail\n" + (mailList.Count + 1);
Image img = Image.FromFile(Imagepath);
int width = img.Width;
using (Graphics G = Graphics.FromImage(img))
using (Font font = new Font("Arial", 7f))
{
SizeF s = G.MeasureString(mailName, font, width);
G.DrawString(mailName, font, Brushes.Black,
(width - s.Width) / 2, img.Height - s.Height - 1);
}
Clipboard.SetImage(img);
rTB_test.Paste();
rTB_test.SelectionStart = rTB_test.TextLength - 1;
rTB_test.SelectionLength = 1;
mailList.Add(rTB_test.SelectedRtf.GetHashCode(), mi);
rTB_test.SelectionStart = rTB_test.TextLength;
rTB_test.SelectionLength = 0;
}
Microsoft.Office.Interop.Outlook.Application _Outlook = null;
Dictionary<int, Microsoft.Office.Interop.Outlook.MailItem> mailList =
new Dictionary<int, Microsoft.Office.Interop.Outlook.MailItem>();
private void rTB_test_DoubleClick(object sender, EventArgs e)
{
var ss = rTB_test.SelectionStart;
var sl = rTB_test.SelectionLength;
int hash = rTB_test.SelectedRtf.GetHashCode();
if (sl == 1 && mailList.Keys.Contains(hash))
{
Microsoft.Office.Interop.Outlook.MailItem mi = mailList[hash];
}
}
void lbl_MouseDoubleClick(object sender, MouseEventArgs e)
{
Microsoft.Office.Interop.Outlook.MailItem mi =
(Microsoft.Office.Interop.Outlook.MailItem)((Label)sender).Tag;
}
void Startup()
{
_Outlook = new Microsoft.Office.Interop.Outlook.Application();
}
private void Form1_DragEnter(object sender, DragEventArgs e)
{
e.Effect = DragDropEffects.Copy;
}
, , Outlookexplorer.
UPDATE
TaW, :

, , ... - "iconcreation".
!