Cómo agregar dinámicamente un menú MenuStrip en C#
Primero puede agregarlo manualmente en el diseñador, luego buscar el código correspondiente en Designer.cs y cortarlo, de la siguiente manera
private System.Windows.Forms.MenuStrip menuStrip1;
System.Windows.Forms.ToolStripMenuItem privado aAAToolStripMenuItem;
System.Windows.Forms.ToolStripMenuItem privado bBBToolStripMenuItem;
Botón de anulación privado1_Click(remitente del objeto, EventArgs e)
{
this.menuStrip1 = nuevo System.Windows.Forms.MenuStrip();
this.aAAToolStripMenuItem = nuevo System.Windows.Forms.ToolStripMenuItem(
this.bBBToolStripMenuItem = nuevo System.Windows.Forms.ToolStripMenuItem()
//
// menuStrip1
//
this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.aAAToolStripMenuItem});
this. menuStrip1.Location = nuevo System.Drawing.Point(0, 0);
this.menuStrip1.Name = "menuStrip1";
this.menuStrip1.Size = nuevo System.Drawing .Size(524, 24);
this.menuStrip1.TabIndex = 3;
this.menuStrip1.Text = "menuStrip1"
//
// aAAToolStripMenuItem
//
this.aAAToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.bBBToolStripMe
nuItem});
this.aAAToolStripMenuItem.Name = "aAAToolStripMenuItem";
this.aAAToolStripMenuItem.Size = nuevo System.Drawing.Size(40, 20);
this.aAAToolStripMenuItem.Text = "AAA";
//
// bBBToolStripMenuItem
//
esto. bBBToolStripMenuItem.Name = "bBBToolStripMenuItem";
this.bBBToolStripMenuItem.Size = nuevo System.Drawing.Size(152, 22);
this.bBBToolStripMenuItem.Text = "BBB";
this.bBBToolStripMenuItem.Click = new System.EventHandler(this.bBBToolStripMenuItem_Click
//
//Form1
/ /
this.Controls.Add(this.menuStrip1);
}
private void bBBToolStripMenuItem_Click(objeto remitente, EventArgs e)
{
MessageBox.Show("BBB");
}