zoukankan      html  css  js  c++  java
  • C#TreeView 添加 右键快捷菜单

    TreeView添加快键菜单有两种方法:

    一种就是使用TreeView的ContextMenuStrip属性,添加一个新ContextMenuStrip,这个方法非常的简答直接,缺点是右键菜单是整个控件响应的,也就是说即使没有右键选中节点也是会触发快捷菜单的显示

    这种方法里获取哪一个的node选中是通过这个方法:TreeNode curNode = this.trvFolder.GetNodeAt(e.X, e.Y)

    另一种是创建ContextMenuStrip,并且使用TreeView的NodeMouseClick事件,在事件中实现为:

    private void trvFolder_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
            {
                if (e.Button == MouseButtons.Right)
                {
                    Point pos = new Point(e.Node.Bounds.X + e.Node.Bounds.Width, e.Node.Bounds.Y + e.Node.Bounds.Height / 2);
                    this.cmsFolderMenu.Show(this.trvFolder, pos);
                }
    }
  • 相关阅读:
    P6007 [USACO20JAN]Springboards G
    CF1000F One Occurrence
    P6100 [USACO19FEB]Painting the Barn G
    P5838 [USACO19DEC]Milk Visits G
    P4085 [USACO17DEC]Haybale Feast
    P4267 [USACO18FEB]Taming the Herd
    P1712 [NOI2016]区间
    CF786B Legacy
    P5665 划分
    NOI2020网上同步赛 游记
  • 原文地址:https://www.cnblogs.com/rogerroddick/p/3027311.html
Copyright © 2011-2022 走看看