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 { } }