当TreeView执行拖拽事件, 有什么办法使状态能像Windows的文件夹那样, 无论何时按住Ctrl键就会变成copy状态, 放开Ctrl键就变成move状态。 我按照MSDN上的例子试验了很多次, 每一次把effect改变, 值虽然是改变了, 但它的状态就变成none,弄的小弟好郁闷。如果有这方面经验的朋友请顶一下。 谢谢了。

解决方案 »

  1.   

    可否考虑动态捕捉CTRL键,参考:protected void Edit_KeyDown(object sender, KeyEventArgs e)
    {
      if (e.KeyCode == Keys.Left || e.KeyCode == Keys.Right )
    return;

      else
      {
    if(e.Control )
             {
       if(e.KeyCode ==Keys.C)
       {
    e.Handled = true;
    this.CopyClipBoard();
       }
      if(e.KeyCode ==Keys.V )
      {
    e.Handled = true;
    this.PasteClipBoard();
    }
      

  2.   

    你所说的MSDN的例子在哪里?
    能不能把你拖动的那部分代码贴出来看看?
      

  3.   

    private void treeView_MyPre_DragOver(object sender, System.Windows.Forms.DragEventArgs e)
    {
    // Retrieve the client coordinates of the mouse position.
    Point targetPoint = treeView_MyPre.PointToClient(new Point(e.X, e.Y)); // Select the node at the mouse position.
    treeView_MyPre.SelectedNode = treeView_MyPre.GetNodeAt(targetPoint); if ((e.KeyState & 8) == 8 )//&& 
    //(e.AllowedEffect & DragDropEffects.Copy) == DragDropEffects.Copy) 
    {
    // CTL KeyState for copy.
    e.Effect = DragDropEffects.Copy;

    else //if ((e.AllowedEffect & DragDropEffects.Move) == DragDropEffects.Move) 
    {
    // By default, the drop action should be move, if allowed.
    e.Effect = DragDropEffects.Move;
    } }
      

  4.   

    上面就是我的代码, 当移动拖拽中碰触其他TreeNode,就判断Ctrl键是否按下了。 可是在改变效果时,如果原来是Move状态, 改变为Copy状态时, 就不可以。 为什么啊。
      

  5.   

    并不是因为不能获知Ctrl键是否按下的原因, 是因为改变拖拽状态时不起作用。请高手快点帮忙啊!!!!!!!!
      

  6.   

    可以的啊。你有没有犯一个低级错误:你的treeview的AllowDrop设为true了吗?
      

  7.   

    只是在拖拽时无法从copy改变为move, 相反也是。