1

以下代码拒绝在鼠标右键单击时进行拖放。当我右键单击鼠标时,我确实看到了正确的上下文菜单,但我无法拖放,尽管我确实有 DragDrop、DragEnter 和 DragOver 的事件处理程序。是因为我不能有上下文菜单并在同一次右键单击时拖放吗?我究竟做错了什么?非常感激您的帮忙。

private void treeList1_MouseDown(object sender, MouseEventArgs e)
{
    TreeList tree = sender as TreeList;
    Point pt = tree.PointToClient(MousePosition);
    TreeListHitInfo info = tree.CalcHitInfo(pt);

    if (e.Button == MouseButtons.Right && ModifierKeys == Keys.None && tree.State == TreeListState.Regular)
    {
        if (nodeType == typeof(X))
        {
            tree.ContextMenuStrip = XContextMenu;
            tree.FocusedNode = info.Node;
            treeList1.AllowDrop = true;
            tree.AllowDrop = true;
        }
        currentFocusNode = tree.FocusedNode;
        return;
    }
}
4

2 回答 2

1

您没有调用DoDragDrop方法。

这是使用 DragDrop的示例

在您的示例中,在return;

treeList1.DoDragDrop(currentFocusNode, DragDropEffects.Copy);
于 2013-02-04T15:25:25.570 回答
1

例如,这是如何对 listView 进行拖放操作:

private void Form1_Load(object sender, EventArgs e)
{
    listView1.AllowDrop = true;
    listView1.DragDrop += new DragEventHandler(listView1_DragDrop);
    listView1.DragEnter += new DragEventHandler(listView1_DragEnter);
}

void listView1_DragEnter(object sender, DragEventArgs e)
{
    e.Effect = DragDropEffects.Copy;
}

void listView1_DragDrop(object sender, DragEventArgs e)
{
    listView1.Items.Add(e.Data.ToString());
}
于 2013-02-04T16:11:29.117 回答