Dynamic Update of ContectMenu with new

May 14, 2013 at 9:31 AM
protected override System.Windows.Forms.ContextMenuStrip CreateMenu()
{
  var menu = new ContextMenuStrip();
  var itemMovieSearch = new ToolStripMenuItem { Text = "Movies" };
  foreach (var filePath in SelectedItemPaths)
  {
    var directoryname = new DirectoryInfo(filePath).Name;
    itemMovieSearch.DropDown.Items.Add(directoryname);
  }
  itemMovieSearch.Click += (server, args) => SearchMovie();
  menu.Items.Add(itemMovieSearch);
  return menu;
}
Can I overide some other function get dynamic ContextMenuStrip . I want to display diffrent SubMenuItem depending on what folder i clicking on. This sample just works on first folder i rightklick. Stays the same on all folders click on after that.

Like 7z gives option that zip the file foldername.zip depending on what folder you are right clicking on.

Regards
Johan
Coordinator
May 19, 2013 at 3:45 PM
Hi,

I think that at the moment, based on how the context menus are built, this is not possible to do by changing the context menu items - the items are built when needed (i.e. on the first right click of an object that is targetted by the extension) and the the menu is re-used.

However, I think that the items created can be customised at a later point by making them owner draw items. In this case, the extension takes the responsibility to drawing the item too. This would allow you to draw different text etc based on what is selected.

They interfaces that would have to be implemented are:

IContextMenu2 - http://msdn.microsoft.com/en-us/library/windows/desktop/bb776091
IContextMenu3 - http://msdn.microsoft.com/en-us/library/windows/desktop/bb776086

I'll attempt to get them implemented in the next version of the library.
Coordinator
May 19, 2013 at 3:46 PM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.
May 31, 2013 at 8:34 AM
Thx