Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add a submenu item to a MenuStrip?

Tags:

c#

winforms

OK so I have a MenuStrip called Form1.menuStrip1. Form1.menuStrip1 has two items horizontally called Menu and Lists. What I want to do is add a new submenu item to the Lists menu. I have a string called mystring, and I want that to be the title of the new Item.

Something like this

void AddItem(string mystring) 
{ 
   // add mystring 
}
like image 336
Eric Vi4ing Avatar asked Jul 27 '12 06:07

Eric Vi4ing


1 Answers

here is the sample

ToolStripMenuItem fileToolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem();
ToolStripMenuItem loadLogsToolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem();
fileToolStripMenuItem1.Name = "File";
loadLogsToolStripMenuItem1.Name ="Logs";

this.fileToolStripMenuItem1.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
            this.loadLogsToolStripMenuItem1
}

then you would have File->Logs if you want to add more subItem to File just use add more after this.loadLogsToolStripMenuItem1.

like image 137
Ehsan Avatar answered Oct 17 '22 18:10

Ehsan