void treeView1_ItemDrag(object sender, ItemDragEventArgs e)
{
DoDragDrop(e.Item, DragDropEffects.Move);
}
void treeView1_DragEnter(object sender, DragEventArgs e)
{
e.Effect = DragDropEffects.Move;
}
void treeView1_DragDrop(object sender, DragEventArgs e)
{
if (!e.Data.GetDataPresent("System.Windows.Forms.TreeNode", false))
{
MessageBox.Show("不是有效的树节点!");
return;//=========>
}
// 获取移动到的节点
Point vPoint = ((TreeView)sender).PointToClient(new Point(e.X, e.Y));
TreeNode vToNode = ((TreeView)sender).GetNodeAt(vPoint);
// 需拖放的节点
TreeNode vNode = (TreeNode)e.Data.GetData("System.Windows.Forms.TreeNode");
string s = moveNode(vNode, vToNode);
if (!string.IsNullOrEmpty(s)) MessageBox.Show(s);
}