.net winform控件监听鼠标左键,右键,双击左键,双击右键

 private void AntgisToolBoxTree_MouseDown(object sender, MouseEventArgs e)
    {
      TreeListHitInfo treeListHitInfo = this.CalcHitInfo(new Point(e.X, e.Y));
      TreeListNode node = treeListHitInfo.Node;
      if (treeListHitInfo.HitInfoType == HitInfoType.Button)
        return;
      this.OptionsBehavior.Editable = false;
      //鼠标右键
      if (e.Button == MouseButtons.Right)
      {
        if (node == null)
        {
          this.FocusedNode = (TreeListNode) null;
          this.CloseEditor();
          this.Selection.Clear();
          this.popupMenu3.ShowPopup(Control.MousePosition);
        }
        else
        {
          this.FocusedNode = node;
          if (!node.HasChildren)
          {
            if (node.StateImageIndex <= 1)
              this.popupMenu2.ShowPopup(Control.MousePosition);
            else
              this.popupMenu1.ShowPopup(Control.MousePosition);
          }
          else
            this.popupMenu2.ShowPopup(Control.MousePosition);
        }
      }
      //鼠标左键
      else if (e.Button == MouseButtons.Left)
      {
        if (node == null)
        {
          this.CloseEditor();
          this.Selection.Clear();
        }
       //e.Clicks = 2表示双击鼠标左键
        else if (e.Clicks != 2)
          node.Expanded = !node.Expanded;
      }
    }
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容