【发布时间】:2020-02-18 05:36:05
【问题描述】:
当将项目从 Outlook 电子邮件拖到 Winforms 应用程序时(控件是 DevExpress 的 GalleryControl,即使我在 DragEnter 事件处理程序中手动设置了“DragDropEffects.Move”,DragDrop 事件也不会触发。(已确认这是开火)
但是 DragDrop 事件只会在从 Windows 资源管理器中拖动普通文件时触发。
private async void gcImages_DragDrop(object sender, DragEventArgs e)
{
string[] fileNames = null;
if (e.Data.GetDataPresent(DataFormats.FileDrop, false) == true)
{
fileNames = (string[])e.Data.GetData(DataFormats.FileDrop);
}
else if (e.Data.GetDataPresent("FileGroupDescriptor"))
{
OutlookDataObject dataObject = new OutlookDataObject(e.Data);
string[] filenames = (string[])dataObject.GetData("FileGroupDescriptor");
}
// do stuff async with file names
}
private void gcImages_DragEnter(object sender, DragEventArgs e)
{
// This event fires, no matter what i drag onto it. (Files from explorer, attachments from Outlook etc)
// However even after setting the effect as per below, the cursor still shows the 'not allowed' symbol.
e.Effect = DragDropEffects.Move;
}
我在控件上启用了AllowDrop = true,它可以完美地与 Windows 资源管理器文件配合使用,但不能与 Outlook 文件配合使用。
奇怪的是 DragEnter 事件正在触发,但 DragDrop 事件不会与 Outlook 附件一起触发。
【问题讨论】:
-
您可能会遇到低权限进程无法拖放到高权限应用程序的限制。
-
无法复制,使用不同类型的用户 (Outlook 2016/x64)。该对象包含
FILEDESCRIPTORW结构的数组。 MemoryStream 的第一个字节包含结构的数量。这些结构返回附件的文件名,而FileContents格式返回包含附件字节的 MemoryStream。在标准 WinForms 控件上拖放。尝试使用具有不同用户权限的非 DevExpress 控件来测试在您的上下文中有效的方法。 -
设法让它与 Outlook 2019 一起使用,使用的是 2013 吗?知道为什么会这样吗?
标签: c# winforms outlook drag-and-drop idataobject