美文网首页
.net winform控件监听鼠标左键,右键,双击左键,双击右

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

作者: 清远_03d9 | 来源:发表于2019-08-18 19:03 被阅读0次
 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;
      }
    }

相关文章

网友评论

      本文标题:.net winform控件监听鼠标左键,右键,双击左键,双击右

      本文链接:https://www.haomeiwen.com/subject/kdkdsctx.html