Search code examples
c#winformsmenustrip

creating a dynamic "recently opened files" menu


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.


Solution

  • 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);
        }