Example #1
0
 private void ListDragTarget_DragOver(object sender, DragEventArgs e)
 {
     // Determine whether string data exists in the drop data. If not, then
     // the drop effect reflects that the drop cannot occur.
     if (!e.Data.GetDataPresent(typeof(System.String)))
     {
         e.Effect = DragDropEffects.None;
         DropLocationLabel.Text = "None - no string data.";
         return;
     }
     // Set the effect based upon the KeyState.
     if ((e.KeyState & (8 + 32)) == (8 + 32) &&
         (e.AllowedEffect & DragDropEffects.Link) == DragDropEffects.Link)
     {
         // KeyState 8 + 32 = CTL + ALT
         // Link drag-and-drop effect.
         e.Effect = DragDropEffects.Link;
     }
     else if ((e.KeyState & 32) == 32 &&
              (e.AllowedEffect & DragDropEffects.Link) == DragDropEffects.Link)
     {
         // ALT KeyState for link.
         e.Effect = DragDropEffects.Link;
     }
     else if ((e.KeyState & 4) == 4 &&
              (e.AllowedEffect & DragDropEffects.Move) == DragDropEffects.Move)
     {
         // SHIFT KeyState for move.
         e.Effect = DragDropEffects.Move;
     }
     else if ((e.KeyState & 8) == 8 &&
              (e.AllowedEffect & DragDropEffects.Copy) == DragDropEffects.Copy)
     {
         // CTL KeyState for copy.
         e.Effect = DragDropEffects.Copy;
     }
     else if ((e.AllowedEffect & DragDropEffects.Move) == DragDropEffects.Move)
     {
         // By default, the drop action should be move, if allowed.
         e.Effect = DragDropEffects.Move;
     }
     else
     {
         e.Effect = DragDropEffects.None;
     }
     // Get the index of the item the mouse is below.
     // The mouse locations are relative to the screen, so they must be
     // converted to client coordinates.
     indexOfItemUnderMouseToDrop =
         ListDragTarget.IndexFromPoint(ListDragTarget.PointToClient(new Point(e.X, e.Y)));
     // Updates the label text.
     if (indexOfItemUnderMouseToDrop != ListBox.NoMatches)
     {
         DropLocationLabel.Text = "Drops before item #" + (indexOfItemUnderMouseToDrop + 1);
     }
     else
     {
         DropLocationLabel.Text = "Drops at the end.";
     }
 }
Example #2
0
 private void DeleteBox_DragDrop(object sender, DragEventArgs e)
 {
     IndexOfItemUnderMouseToDrop = ListBox.NoMatches;
     AlignTaskEnable();
     AlignHelpMessage();
     ListDragTarget.Invalidate();
 }
Example #3
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();
        }
Example #4
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;
        }
Example #5
0
        private void ListDragSource_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
        {
            if ((e.Button & MouseButtons.Left) == MouseButtons.Left)
            {
                if (!ListDragTarget.Lock)
                {
                    bool draggable = true;
                    if (sender == ListDragTarget)
                    {
                        draggable = ListDragTarget.RemovableForTaskFlow(IndexOfItemUnderMouseToDrag);
                    }
                    if (!draggable)
                    {
                        Cursor.Current = Cursors.No;
                    }
                    // If the mouse moves outside the rectangle, start the drag.
                    if (draggable && dragBoxFromMouseDown != Rectangle.Empty &&
                        !dragBoxFromMouseDown.Contains(e.X, e.Y))
                    {
                        // Create custom cursors for the drag-and-drop operation.
                        try
                        {
                            TaskListBox ctrl = (TaskListBox)sender;

                            MyNormalCursor = ctrl.CreateCursor(IndexOfItemUnderMouseToDrag, true);
                            MyNodropCursor = ctrl.CreateCursor(IndexOfItemUnderMouseToDrag, false);
                        }
                        catch
                        {
                        }
                        finally
                        {
                            // The screenOffset is used to account for any desktop bands
                            // that may be at the top or left side of the screen when
                            // determining when to cancel the drag drop operation.
                            screenOffset = SystemInformation.WorkingArea.Location;
                            object data = ((TaskListBox)sender).GetDragData(IndexOfItemUnderMouseToDrag);
                            if (sender == ListDragTarget)
                            {
                                ((TaskListBox)sender).RemoveAt(IndexOfItemUnderMouseToDrag);
                                AlignHelpMessage();
                            }
                            // Proceed with the drag-and-drop, passing in the list item.
                            DragDropEffects dropEffect = ((TaskListBox)sender).DoDragDrop(data, DragDropEffects.All | DragDropEffects.Copy);

                            // Dispose of the cursors since they are no longer needed.
                            if (MyNormalCursor != null)
                            {
                                MyNormalCursor.Dispose();
                            }
                            if (MyNodropCursor != null)
                            {
                                MyNodropCursor.Dispose();
                            }
                        }
                    }
                }
            }
            else
            {
                if (sender is TaskListBox)
                {
                    TaskListBox listbox         = (TaskListBox)sender;
                    int         newHoveredIndex = listbox.IndexFromPoint(e.Location);
                    if (newHoveredIndex == -1)
                    {
                        this.ToolTip.ShowAlways = false;
                    }
                    if (hoveredIndex != newHoveredIndex)
                    {
                        hoveredIndex = newHoveredIndex;
                        if (hoveredIndex > -1)
                        {
                            AbstractProcessingTask task = listbox.Get(hoveredIndex);
                            if (task != null)
                            {
                                this.ToolTip.Active = false;
                                this.ToolTip.SetToolTip(listbox, task.ToolTip);
                                this.ToolTip.Active     = true;
                                this.ToolTip.ShowAlways = true;
                            }
                        }
                    }
                }
            }
        }