代码之家  ›  专栏  ›  技术社区  ›  Julien Poulin

执行拖放操作时出现异常

  •  7
  • Julien Poulin  · 技术社区  · 16 年前

    我有一个WinForms应用程序,可以在两个TreeViews之间进行拖放操作。

    在某些时候,我想拒绝底层业务实现中的操作,所以我抛出了一个Exception。我可以在输出窗口中看到异常,但问题是我在UI中看不到它,它也不会崩溃。

    private TreeView tvLeft;
    private TreeView tvRight;
    private Dictionary<string, int> dico = new Dictionary<string, int>();
    
    void tvLeft_DragDrop(object sender, DragEventArgs e) {
    
      if (e.Data.GetDataPresent(typeof(TreeNode))) {
    
        var tnSource = (TreeNode) e.Data.GetData(typeof(TreeNode));
        var tnDestination = tvLeft.GetNodeAt(tvLeft.PointToClient(new Point(e.X, e.Y)));
    
        // if I drag-drop the same node twice, there sould be an Exception
        // since the key is already in the dictionary...
        // ...but I get no Exception in the UI, the Application.ThreadException
        // or Appomain.CurrentDomain.UnhandledException handlers
        dico.Add(tnSource.Name, (new Random()).Next());
    
      }
    
    }
    
    2 回复  |  直到 16 年前
        1
  •  12
  •   Viper    16 年前

    我在网上找到了这个解释:

    即使在同一个应用程序中进行拖放,也可以通过标准的OLE拖放机制来处理拖放。从OLE的角度来看,它处理两个应用程序,源和目标,并适当地将它们解耦。自从OLE问世以来,它已经存在了很长时间。NET,OLE没有。NET异常,因此无法将异常从目标传递回源。即使可以,为什么来源要关心目标无法执行投放?

    here

        2
  •  0
  •   Simon P Stevens    16 年前

    here

    推荐文章