Dmitry Makovetskiyd
Dmitry Makovetskiyd

Reputation: 7053

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.

Upvotes: 1

Views: 1784

Answers (2)

Bas
Bas

Reputation: 27115

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

Upvotes: 1

SLaks
SLaks

Reputation: 888273

You need to create ToolStripMenuItems 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.

Upvotes: 0

Related Questions