컴퓨터 지식 네트워크 - 컴퓨터 지식 - C#에서 MenuStrip 메뉴를 동적으로 추가하는 방법

C#에서 MenuStrip 메뉴를 동적으로 추가하는 방법

먼저 디자이너에서 수동으로 추가한 다음 Designer.cs에서 해당 코드를 찾아서 다음과 같이 잘라낼 수 있습니다.

private System.Windows.Forms.MenuStrip menuStrip1;

private System.Windows.Forms.ToolStripMenuItem aAAToolStripMenuItem;

private System.Windows.Forms.ToolStripMenuItem bBBToolStripMenuItem;

private void 버튼1_Click(객체 전송자, EventArgs e)

{

this.menuStrip1 = 새로운 System.Windows.Forms.MenuStrip();

this.aAAToolStripMenuItem = 새로운 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.드로잉.Point(0, 0);

this.menuStrip1.Name = "menuStrip1";

this.menuStrip1.Size = 새로운 System.드로잉 .Size(524, 24);

this.menuStrip1.TabIndex = 3;

this.menuStrip1.Text = "menuStrip1";

//

// aAAToolStripMenuItem

//

this.aAAToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {

this.bBBToolStripMenuItem});

this.aAAToolStripMenuItem.Name = "aAAToolStripMenuItem";

this.aAAToolStripMenuItem.Size = new System.드로잉.Size(40, 20);

this.aAAToolStripMenuItem.Text = "AAA";

//

// bBBToolStripMenuItem

//

this.bBBToolStripMenuItem.Name = "bBBToolStripMenuItem";

this.bBBToolStripMenuItem.Size = new 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(개체 전송자, EventArgs e)

{

MessageBox.Show("BBB")

}

上篇: 23 모니터 도트 피치 下篇: Ios 에는 어떤 재미있는 휴대폰 공포 게임이 있나요?
관련 내용