/// <summary> /// Begins a drag-and-drop operation, with an image attached. /// </summary> /// <param name="data">The data to drag.</param> /// <param name="allowedEffects">One of the DragDropEffects values.</param> /// <param name="dragImage">The image to attach to the cursor</param> /// <param name="cursorOffset">The offset within the image that the cursor attaches to.</param> /// <returns>A value from the DragDropEffects enumeration that represents the final effect that was performed during the drag-and-drop operation.</returns> public DragDropEffects DoDragDrop(object data, DragDropEffects allowedEffects, Bitmap dragImage, Point cursorOffset) { var adviseConnection = 0; try { DragDropHelper.SetFlags(1); // Create IDataObject m_dragData = new DragDropDataObject(); // attach image if we have one. if (dragImage != null) { DragDropHelper.InitializeFromBitmap(m_dragData, dragImage, cursorOffset); } // We need to listen for drop description changes. If a drop target // changes the drop description, we shouldn't provide a default one. var formatEtc = OleConverter.CreateFormat("DropDescription"); var hr = m_dragData.DAdvise(ref formatEtc, 0, new AdviseSink(m_dragData), out adviseConnection); if (hr != 0) { Marshal.ThrowExceptionForHR(hr); } // associate data with it. m_dragData.SetData("DragDropExtender", this); m_dragData.SetData(data); m_owner.GiveFeedback += OnGiveFeedback; m_owner.QueryContinueDrag += OnQueryContinueDrag; return(m_owner.DoDragDrop(m_dragData, allowedEffects)); } finally { m_owner.GiveFeedback -= OnGiveFeedback; m_owner.QueryContinueDrag -= OnQueryContinueDrag; if (m_dragData != null) { // Stop listening to drop description changes m_dragData.DUnadvise(adviseConnection); m_dragData.Dispose(); m_dragData = null; } } }
/// <summary> /// Call this method in the OnDrop if you wish to accept Shell Image drag/drop actions</summary> /// <param name="e">The DragEventArgs from the OnDrop event</param> public static void Drop(DragEventArgs e) { var point = new Point(e.X, e.Y); DragDropHelper.Drop((IComDataObject)e.Data, ref point, (int)e.Effect); }
/// <summary> /// Call this method in the OnDragLeave if you wish to accept Shell Image drag/drop actions</summary> public static void DragLeave() { DragDropHelper.DragLeave(); }
/// <summary> /// Call this method in the OnDragOver if you wish to accept Shell Image drag/drop actions</summary> /// <param name="e">The DragEventArgs from the OnDragOver event</param> public static void DragOver(DragEventArgs e) { var point = new Point(e.X, e.Y); DragDropHelper.DragOver(ref point, (int)e.Effect); }
/// <summary> /// Call this method in the OnDragEnter if you wish to accept Shell Image drag/drop actions</summary> /// <param name="control">The control receiving the OnDragEnter event</param> /// <param name="e">The DragEventArgs from the OnDragEnter event</param> public static void DragEnter(Control control, DragEventArgs e) { var point = new Point(e.X, e.Y); DragDropHelper.DragEnter(control.Handle, (IComDataObject)e.Data, ref point, (int)e.Effect); }