private void treeView_DragDrop(object sender, DragEventArgs e) { TreeNode aNode = CurrentTreeView.GetNodeAt(CurrentTreeView.PointToClient(new Point(e.X, e.Y))); CurrentTreeView.SelectedNode = aNode; XmlNode aNodeElement = aNode.Tag as XmlNode; if (oldNode != null) { oldNode.BackColor = aNode.BackColor; oldNode.ForeColor = aNode.ForeColor; } string[] filesOrFolders = (string[])e.Data.GetData(DataFormats.FileDrop); if (aNodeElement.Name == "Component") { ImportFilesInComponent(aNode, aNodeElement, filesOrFolders); } else if (aNodeElement.Name == "Directory") { ImportFoldersInDirectory(aNode, aNodeElement, filesOrFolders); } }
private void treeView_DragOver(object sender, DragEventArgs e) { TreeNode aNode = CurrentTreeView.GetNodeAt(CurrentTreeView.PointToClient(new Point(e.X, e.Y))); if (oldNode == aNode) { return; } if (e.Data.GetDataPresent(DataFormats.FileDrop)) { XmlNode aNodeElement = aNode.Tag as XmlNode; if (aNodeElement.Name == "Component") { bool filesOnly = true; string[] filesAndFolders = (string[])e.Data.GetData(DataFormats.FileDrop); foreach (string fileOrFolder in filesAndFolders) { if (File.Exists(fileOrFolder) == false) { filesOnly = false; break; } } if (filesOnly) { e.Effect = DragDropEffects.Copy; } else { e.Effect = DragDropEffects.None; } } else if (aNodeElement.Name == "Directory") { bool dirsOnly = true; string[] filesAndFolders = (string[])e.Data.GetData(DataFormats.FileDrop); foreach (string fileOrFolder in filesAndFolders) { if (Directory.Exists(fileOrFolder) == false) { dirsOnly = false; break; } } if (dirsOnly) { e.Effect = DragDropEffects.Copy; } else { e.Effect = DragDropEffects.None; } } else { e.Effect = DragDropEffects.None; } } if (oldNode != null) { oldNode.BackColor = aNode.BackColor; oldNode.ForeColor = aNode.ForeColor; } aNode.BackColor = Color.DarkBlue; aNode.ForeColor = Color.White; oldNode = aNode; }