开发者

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.


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 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜