日期:2014-05-18  浏览次数:20924 次

C# Winform中如何给ContextMenuScript添加子项至第一项
代码如下:

//往右键菜单中添加信息
 ToolStripMenuItem tool = null;
  tool = new ToolStripMenuItem();
  tool.Name = "chatuser_" + item.ChildNodes[0].InnerText.ToString() + "-" + item.ChildNodes[4].InnerText.ToString();
  tool.Text = item.ChildNodes[6].InnerText.ToString() + " (" + item.ChildNodes[9].InnerText.ToString() + ")";
  tool.Click += new EventHandler(contextList_item_Click);
  tool.Size = new System.Drawing.Size(100, 50);
  contextList.Items.RemoveByKey(tool.Name);
  contextList.Items.Add(tool);
这个添加进去了,但是是在最后一个显示,有什么办法能让他显示在第一个呢?

------解决方案--------------------
contextList.Items.Insert(0, tool)
------解决方案--------------------
应该有Insert方法