Пример #1
0
        private void ListDragTarget_DragDrop(object sender, System.Windows.Forms.DragEventArgs e)
        {
            // Ensure that the list item index is contained in the data.
            if (TaskListBox.IsValidDragData(e.Data))
            {
                // Perform drag-and-drop, depending upon the effect.
                if (e.Effect == DragDropEffects.Copy ||
                    e.Effect == DragDropEffects.Move)
                {
                    AbstractProcessingTask task = null;
                    if (TaskListBox.DragDataSource(e.Data) == ListDragTarget)
                    {
                        task = (AbstractProcessingTask)(TaskListBox.DragDataTask(e.Data));
                    }
                    else                     // if we are comming from source list => Create a new instance
                    if (task == null)
                    {
                        task = TaskListBox.DragDataTask(e.Data).Clone();
                    }

                    if (ListDragTarget.IsValidInsertionIndex(IndexOfItemUnderMouseToDrop, task, In))                     // if place is ok
                    {
                        ((TaskListBox)sender).Insert(IndexOfItemUnderMouseToDrop, task);
                    }
                    else if (TaskListBox.DragDataSource(e.Data) == ListDragTarget)                     // if place is not ok, but we came from the destination listbox, we reinsert the task when she come from
                    {
                        ((TaskListBox)sender).Insert(TaskListBox.DragDataIndex(e.Data), task);
                    }
                    ListDragTarget.Invalidate();
                    IndexOfItemUnderMouseToDrop = ListBox.NoMatches;
                }
            }
            AlignTaskEnable();
            AlignHelpMessage();
        }
Пример #2
0
 private void DeleteBox_DragDrop(object sender, DragEventArgs e)
 {
     IndexOfItemUnderMouseToDrop = ListBox.NoMatches;
     AlignTaskEnable();
     AlignHelpMessage();
     ListDragTarget.Invalidate();
 }
Пример #3
0
        private void ListDragTarget_DragOver(object sender, System.Windows.Forms.DragEventArgs e)
        {
            // Determine whether string data exists in the drop data. If not, then
            // the drop effect reflects that the drop cannot occur.
            bool valid = TaskListBox.IsValidDragData(e.Data);

            if (!valid)
            {
                e.Effect = DragDropEffects.None;
                return;
            }

            int lastIndex = IndexOfItemUnderMouseToDrop;

            IndexOfItemUnderMouseToDrop = ListDragTarget.IndexFromPoint(ListDragTarget.PointToClient(new Point(e.X, e.Y)));

            if (sender == ListDragTarget)
            {
                if (IndexOfItemUnderMouseToDrop == -1)
                {
                    IndexOfItemUnderMouseToDrop = ListDragTarget.Count;
                }

                ListDragTarget.Invalidate(lastIndex);
                ListDragTarget.Invalidate(IndexOfItemUnderMouseToDrop);

                if (ListDragTarget.IsValidInsertionIndex(IndexOfItemUnderMouseToDrop, TaskListBox.DragDataTask(e.Data), In))
                {
                    e.Effect = DragDropEffects.Copy;
                    return;
                }
                else
                {
                    IndexOfItemUnderMouseToDrop = -1;
                    e.Effect = DragDropEffects.Move;
                    return;
                }
            }
            e.Effect = DragDropEffects.Move;
        }