天道酬勤,学无止境

右键功能设计

C# Treeview右键功能设计

点击TreeView的事件,添加一个MouseDown事件private void treeView1_MouseDown(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Right) { Point Click = new Point(e.X, e.Y); TreeNode CurrentNode = treeView1.GetNodeAt(Click); nameStr = CurrentNode.Text.ToString(); Tagnum = Convert.ToInt32(CurrentNode.Tag.ToString()); if (CurrentNode != null) { switch (CurrentNode.Tag.ToString())//根据不同的名字或者其他信息实现右键功能 { case "2": CurrentNode.ContextMenuStrip = contextMenuStrip2; break; } } } }来源:https://blog.51cto.com/smartboy/1564878

2021-05-11 18:29:50    分类:博客    treeview   右键功能设计