【发布时间】:2011-03-11 16:43:19
【问题描述】:
我有一个可以在表单周围拖动的 UserControl。当控件意外地从我的表单拖到桌面时,我遇到了第一次机会异常(例如):
A first chance exception of type 'System.Runtime.InteropServices.COMException' occurred in System.Windows.Forms.dll
Additional information: Invalid FORMATETC structure (Exception from HRESULT: 0x80040064 (DV_E_FORMATETC))
当我开始拖放过程时,我传入了一个 Control 类型的对象。它不是可序列化的,我也不希望它是。有没有办法解决这个问题,或者是否可以处理将对象拖到主机表单之外?
调用栈:
> System.Windows.Forms.dll!System.Windows.Forms.DataObject.GetDataIntoOleStructs(ref System.Runtime.InteropServices.ComTypes.FORMATETC formatetc, ref System.Runtime.InteropServices.ComTypes.STGMEDIUM medium) + 0x175 bytes
System.Windows.Forms.dll!System.Windows.Forms.DataObject.System.Runtime.InteropServices.ComTypes.IDataObject.GetDataHere(ref System.Runtime.InteropServices.ComTypes.FORMATETC formatetc, ref System.Runtime.InteropServices.ComTypes.STGMEDIUM medium) + 0x70 bytes
System.Windows.Forms.dll!System.Windows.Forms.DataObject.System.Runtime.InteropServices.ComTypes.IDataObject.GetData(ref System.Runtime.InteropServices.ComTypes.FORMATETC formatetc, out System.Runtime.InteropServices.ComTypes.STGMEDIUM medium) + 0x152 bytes
[Native to Managed Transition]
这是另一个堆栈,但是 VS2010 挂起,所以我无法复制和粘贴它。
【问题讨论】:
-
我不希望我的对象被拖到桌面或其他应用程序中。 MSDN DoDragDrop 声明:如果拖动操作需要与另一个进程中的应用程序互操作,则数据应该是基托管类(String、Bitmap 或 Metafile),或者是实现 ISerializable 或 IDataObject 的对象。
-
是否阻止用户在拖动选项时将控件移出窗口边界?
-
我不想要它的唯一原因是因为我没有用拖到我的窗口之外。问题是程序抛出了异常。
标签: c# winforms exception drag-and-drop