private void NaviBoxEvent_DragDrop(object sender, DragEventArgs e) { if (NaviBox.SelectedItems.Count == 0) { return; } Point cp = NaviBox.PointToClient(new Point(e.X, e.Y)); ListViewItem dragToItem = NaviBox.GetItemAt(cp.X, cp.Y); if (dragToItem == null) { return; } int dragIndex = dragToItem.Index; ListViewItem[] selection = new ListViewItem[NaviBox.SelectedItems.Count]; for (int i = 0; i <= NaviBox.SelectedItems.Count - 1; i++) { selection[i] = NaviBox.SelectedItems[i]; } for (int i = 0; i < selection.GetLength(0); i++) { ListViewItem dragItem = selection[i]; int itemIndex = dragIndex; if (itemIndex == dragItem.Index) { return; } if (dragItem.Index < itemIndex) { itemIndex++; } else { itemIndex = dragIndex + i; } } int targetIndex = NaviBox.InsertionMark.Index; if (targetIndex == -1) { return; } if (NaviBox.InsertionMark.AppearsAfterItem) { targetIndex++; } if (NavigatorBoxControl.IsItADirectory(NavigatorBoxControl.SelectionPath)) { NavigatorBoxControl.CopyDirectory(NavigatorBoxControl.SelectionPath, NavigatorBoxControl.CopyTarget); return; } NavigatorBoxControl.CopyFile(NavigatorBoxControl.SelectionPath, NavigatorBoxControl.CopyTarget); }
private void NaviBoxEvent_DragOver(object sender, DragEventArgs e) { Point targetPoint = NaviBox.PointToClient(new Point(e.X, e.Y)); int targetIndex = NaviBox.InsertionMark.NearestIndex(targetPoint); if (targetIndex > -1) { Rectangle itemBounds = NaviBox.GetItemRect(targetIndex); if (targetPoint.X > itemBounds.Left + (itemBounds.Width / 2)) { NaviBox.InsertionMark.AppearsAfterItem = true; } else { NaviBox.InsertionMark.AppearsAfterItem = false; } } NaviBox.InsertionMark.Index = targetIndex; // setting target path to the location of the cursor Point cp = NaviBox.PointToClient(new Point(e.X, e.Y)); ListViewItem dragToItem = NaviBox.GetItemAt(cp.X, cp.Y); try { if (NavigatorBoxControl.IsItADirectory(NavigatorBoxControl.SelectionPath)) { DirectoryInfo srcDirInfo = new DirectoryInfo(NavigatorBoxControl.SelectionPath); DirectoryInfo tarDirInfo = new DirectoryInfo(dragToItem.ListView.Columns[0].Text); NavigatorBoxControl.CopyTarget = tarDirInfo.FullName + dragToItem.Text + @"\" + srcDirInfo.Name; } else { FileInfo srcFileInfo = new FileInfo(NavigatorBoxControl.SelectionPath); FileInfo tarFileInfo = new FileInfo(dragToItem.ListView.Columns[0].Text); NavigatorBoxControl.CopyTarget = tarFileInfo.FullName + dragToItem.Text + @"\" + srcFileInfo.Name; } } catch { } }
public void Setup() { NaviBox.FullRowSelect = true; NaviBox.View = View.Details; NaviBox.AllowColumnReorder = true; NaviBox.LabelEdit = true; NaviBox.AllowDrop = true; AddHeader(); ListContent(); NaviBox.Refresh(); NaviBox.Click += new EventHandler(NaviBoxEvent_Click); NaviBox.DoubleClick += new EventHandler(NaviBoxEvent_DoubleClick); NaviBox.KeyDown += new KeyEventHandler(NaviBoxEvent_KeyDown); NaviBox.KeyUp += new KeyEventHandler(NaviBoxEvent_KeyUp); NaviBox.AfterLabelEdit += new LabelEditEventHandler(NaviBoxEvent_AfterLabelEdit); NaviBox.DragDrop += new DragEventHandler(NaviBoxEvent_DragDrop); NaviBox.DragEnter += new DragEventHandler(NaviBoxEvent_DragEnter); NaviBox.ItemDrag += new ItemDragEventHandler(NaviBoxEvent_ItemDrag); NaviBox.DragOver += new DragEventHandler(NaviBoxEvent_DragOver); NaviBox.DragLeave += new EventHandler(NaviBoxEvent_DragLeave); }
private void NaviBoxEvent_ItemDrag(object sender, ItemDragEventArgs e) { NavigatorBoxControl.SelectionPath = CurrentDirectoryPath + NaviBox.SelectedItems[0].Text; NaviBox.DoDragDrop(NaviBox.SelectedItems, DragDropEffects.Move); }