WinForm TreeView 右键菜单
判断你的TreeNode的Level,根据Level的不同设置不同的右键菜单,通常触发的是鼠标点击事件
myTreeView.MouseClick += new MouseEventHandler(myTreeView_MouseClick);
void myTreeView_MouseClick(object sender, MouseEventArgs e)
{
myTreeView.ContextMenuStrip = null;
TreeNode selectNode = myTreeView.GetNodeAt(e.X, e.Y);
if (selectNode.Level == 0)
{
myTreeView.ContextMenuStrip = 你的ContextMenuStrip_1
}
else if (selectNode.Level == 1)
{
myTreeView.ContextMenuStrip = 你的ContextMenuStrip_2
}
//... ...
}
myTreeView.MouseClick += new MouseEventHandler(myTreeView_MouseClick);
void myTreeView_MouseClick(object sender, MouseEventArgs e)
{
myTreeView.ContextMenuStrip = null;
TreeNode selectNode = myTreeView.GetNodeAt(e.X, e.Y);
if (selectNode.Level == 0)
{
myTreeView.ContextMenuStrip = 你的ContextMenuStrip_1
}
else if (selectNode.Level == 1)
{
myTreeView.ContextMenuStrip = 你的ContextMenuStrip_2
}
//... ...
}