【发布时间】:2010-09-07 20:44:32
【问题描述】:
我有兴趣捕获一个拖放事件,该事件将从用户将现有 TreeNode 拖动到 TreeView 中的某个位置开始。当用户拖动 TreeNode 时,我有兴趣捕捉节点何时被拖动到两个树节点之间。当用户这样做时,我想在树节点之间显示一个哈希标记,以指定该节点是作为子节点还是作为兄弟节点被删除。此井号标记将显示: - 在目标节点下方(表示源节点将作为目标节点的子节点被删除 要么 - 在左侧的目标节点下方(表示源节点将作为目标节点的兄弟节点被删除),之前或之后...
我使用 DragOver 事件取得了一些进展。当我拖动鼠标时,我正在计算鼠标位置并推导顶部和底部节点的位置..
int threshold = 8; //Joe(hack)
Point mouseLocation = mouseLocation = treeViewConditions.PointToClient(new Point(e.X, e.Y - threshold));
TreeNode topNode = treeViewConditions.GetNodeAt(mouseLocation);
mouseLocation = treeViewConditions.PointToClient(new Point(e.X + threshold, e.Y));
TreeNode bottomNode = treeViewConditions.GetNodeAt(mouseLocation);
if (topNode != null && bottomNode == null)
{
textBoxDescription.Text = "handling top node";
}
else if (topNode == null && bottomNode != null)
{
textBoxDescription.Text = "handling bottom node";
}
else if (topNode != null && bottomNode != null)
{
if (topNode != bottomNode)
{
textBoxDescription.Text = "between!";
}
else if (topNode == bottomNode)
{
}
}
但是,这样做只会让人觉得很脏。我想知道是否有人知道更好的方法来做到这一点。
提前致谢!
【问题讨论】:
标签: c# .net treeview drag-and-drop nodes