I have 3 folders which contains a bunch of subfolders and files. I need to create a ContextMenuStrip with all the folders and files as ToolStripMenuItems (as a tree hierarchy). I know how to hardcode it:
public class CustomApplicationContext : ApplicationContext
{
private NotifyIcon trayIcon;
private ContextMenuStrip contextMenuStrip = new ContextMenuStrip();
ToolStripMenuItem option1 = new ToolStripMenuItem("Option 1");
ToolStripMenuItem option1a = new ToolStripMenuItem("Option 1a");
ToolStripMenuItem option1b = new ToolStripMenuItem("Option 1b");
ToolStripMenuItem option1c = new ToolStripMenuItem("Option 1c");
ToolStripMenuItem option1ca = new ToolStripMenuItem("Option 1ca");
ToolStripMenuItem option2 = new ToolStripMenuItem("Option 2");
ToolStripMenuItem option3 = new ToolStripMenuItem("Option 3");
ToolStripMenuItem option4 = new ToolStripMenuItem("Option 4");
public CustomApplicationContext()
{
contextMenuStrip.Items.AddRange(new ToolStripItem[]
{
this.option1,
this.option2,
this.option3,
this.option4
});
this.option1.DropDownItems.AddRange(new ToolStripItem[]
{
this.option1a,
this.option1b,
this.option1c
});
this.option1c.DropDownItems.AddRange(new ToolStripItem[]
{
this.option1ca
});
trayIcon = new NotifyIcon()
{
Icon = Resources.AppIcon,
ContextMenuStrip = contextMenuStrip,
Visible = true
};
}
}
However, I would like to make it more dynamically so if something change within one of the folders, it'll also be dynamically changed.
How would I be able to do that?