我有興趣捕獲一個拖放事件,該事件將以用戶在TreeView內某處拖動現有TreeNode爲開始。當用戶拖動TreeNode時,我有興趣捕獲節點在兩個樹節點之間拖動的時間。當用戶這樣做時,我想在樹節點之間顯示一個散列標記,以指定該節點是作爲孩子還是作爲兄弟節點在節點內丟棄。此散列標記將顯示: - 位於目標節點下方(以指示源節點將作爲目標節點的子節點 或 - 在左側目標節點的下面(表示源節點將作爲目標節點的同胞),之前或之後.......NET 2.0 C#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)
{
}
}
然而,在這樣做的時候,它只是感覺很髒,我想知道是否有人知道更好的方法來做acc略過這個。
感謝提前一噸!