I want to add a feature to my MenuStrip where I want there to be an option where you can hover over or press the menu option to open开发者_运维问答 recently opened projects .
File---> Recently Opened Projects---> {List of projects.....}
The same kind of option/menu that exists in Microsoft office products (e.g. word 2007).
I know how to get an array of the file names. I just need to know how to put the array of the names at the Sub MenuStrip.
You can add them dynamically in code:
private void menuItem_Click(object sender, EventArgs e)
{
ToolStripMenuItem item = new ToolStripMenuItem();
item.Text = "your file name";
item.Click += new EventHandler(yourEventHandler);
menuItem.DropDownItems.Add(item);
}
You need to create ToolStripMenuItem
s in a loop and call DropDownItems.Add
to add them to your parent menu item.
In the loop, you should add a handler to their Click
event.
精彩评论