C#怎么动态添加MenuStrip的菜单

来源:百度知道 编辑:UC知道 时间:2024/06/07 09:47:36
C#怎么动态(用代码)添加菜单?并且还要有动作

你可以先在设计器里手动添加,然后在Designer.cs里找到相应代码剪切过来就行,如下

private System.Windows.Forms.MenuStrip menuStrip1;
private System.Windows.Forms.ToolStripMenuItem aAAToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem bBBToolStripMenuItem;
private void button1_Click(object sender, EventArgs e)
{
this.menuStrip1 = new System.Windows.Forms.MenuStrip();
this.aAAToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.bBBToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
//
// menuStrip1
//
this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.aAAToolStripMenuItem});
this.menuStrip1.Location = new System.Drawing.Point(0, 0);
this.menuStrip1.Name = "menuStrip1";
this.menuStrip1.Size