/// <summary> /// Starts the drag and drop operation /// </summary> /// <param name="effect">The desired drag and drop effect like Copy, Move or Link</param> private void Start(DragDropEffects effect) { StopTrackingForDeferredStartOnMouseMove(); var canProceed = _conditionEvaluator.Invoke(); if (!canProceed) { return; } _previewFormController = new PreviewFormController(); var preview = _previewEvaluator?.Invoke(); var hookId = IntPtr.Zero; var resultEffect = DragDropEffects.None; try { hookId = NativeMethods.HookMouseMove(() => _previewFormController.Move()); _previewFormController.Start(SourceControl, _effects, preview, _cursorOffset); var data = Data == null ? (object)new NullPlaceholder() : Data; resultEffect = SourceControl.DoDragDrop(data, effect); } finally { NativeMethods.RemoveHook(hookId); // always send "canceled" here -> if the drag and drop operation was successful // this call is too late and will not do anything _previewFormController.Stop(null, wasCancelled: true); CleanUp(); } }
/// <summary> /// Starts the drag and drop operation /// </summary> /// <param name="effect">The desired drag and drop effect like Copy, Move or Link</param> private void Start(DragDropEffects effect) { StopTrackingForDeferredStartOnMouseMove(); var canProceed = _conditionEvaluator.Invoke(); if (!canProceed) { return; } OnSafeguardedBeforeStart(); _previewFormController = new PreviewFormController(); var preview = _previewEvaluator?.Invoke(); var hookId = IntPtr.Zero; var resultEffect = DragDropEffects.None; try { if (_allowMouseHooks) { hookId = NativeMethods.HookMouseMove(() => _previewFormController.Move()); } else { SourceControl.GiveFeedback += SourceControl_GiveFeedback; } var offset = _offsetEvaluator?.Invoke(CalculatePreviewSize()) ?? Point.Empty; _previewFormController.Start(SourceControl, _effects, preview, offset); var data = Data == null ? (object)new NullPlaceholder() : Data; OnSafeguardedAfterStart(); resultEffect = SourceControl.DoDragDrop(data, effect); } finally { if (_allowMouseHooks) { NativeMethods.RemoveHook(hookId); } else { SourceControl.GiveFeedback -= SourceControl_GiveFeedback; } // always send "canceled" here -> if the drag and drop operation was successful // this call is too late and will not do anything _previewFormController.Stop(null, wasCancelled: true); InvokeCancelIfNotDroppedAction(); CleanUp(); } }