积极答复者
C#如何动态添加右键菜单的子菜单

问题
-
我先动态创建三个菜单项:1、2、3:
private ContextMenuStrip cms = new ContextMenuStrip();
for(int i = 1; i <= 3; i++)
{
ToolStripMenuItem tsm = new ToolStripMenuItem(i.ToString());
cms.Items.Add(tsm);
}
现在想要动态地为每个菜单项各自添加两个子菜单,怎样才能添加DropDownItem?
for(int i = 1; i <= 2; i++)
{
ToolStripMenuItem tsm = new ToolStripMenuItem(i.ToString());
//在这里如何添加DropDownItem?
}
答案
-
private ContextMenuStrip cms = new ContextMenuStrip(); private void Form4_Load(object sender, EventArgs e) { for (int i = 1; i <= 3; i++) { ToolStripMenuItem tsm = new ToolStripMenuItem(i.ToString()); for (int j = 1; j <= 2; j++) { ToolStripMenuItem tsmz = new ToolStripMenuItem(j.ToString()); tsm.DropDown.Items.Add(tsmz); } cms.Items.Add(tsm); } this.ContextMenuStrip = cms; }
http://blog.csdn.net/zx13525079024
- 已标记为答案 栾涅 2012年7月2日 2:37
全部回复
-
private ContextMenuStrip cms = new ContextMenuStrip(); private void Form4_Load(object sender, EventArgs e) { for (int i = 1; i <= 3; i++) { ToolStripMenuItem tsm = new ToolStripMenuItem(i.ToString()); for (int j = 1; j <= 2; j++) { ToolStripMenuItem tsmz = new ToolStripMenuItem(j.ToString()); tsm.DropDown.Items.Add(tsmz); } cms.Items.Add(tsm); } this.ContextMenuStrip = cms; }
http://blog.csdn.net/zx13525079024
- 已标记为答案 栾涅 2012年7月2日 2:37