I have a file listing in my application and I would like to allow people to right-click on an item and show the Windows Explorer context menu. I'm assuming I would need to use the IContextMenu interface, but I'm not really sure where to start.
views:
2469answers:
4I have written a library that might be able to help you. You could use the controls provided by the library, or if you don't want to do that, looking through the code may give you an answer.
You can find the library at: http://gong-shell.sourceforge.net/
Please let me know if this helped!
There's a very good tutorial (albeit in C++) about hosting an IContextMenu on Raymond Chen's blog in 11 parts (in order):
Take a look at this project http://www.codeproject.com/KB/miscctrl/FileBrowser.aspx
It's file browser in C#, it can show shell context menus for files.
I found a great Code Project article that encapsulates everything very nicely into one class!
It's as easy as the following code snippet:
// Sample code
ShellContextMenu ctxMnu = new ShellContextMenu();
FileInfo[] arrFI = new FileInfo[1];
arrFI[0] = new FileInfo(this.treeMain.SelectedNode.Tag.ToString());
ctxMnu.ShowContextMenu(arrFI, this.PointToScreen(new Point(e.X, e.Y)));
The only irksome thing is that it takes either an array of FileInfo[] or an array of DirectoryInfo[] although it was VERY easy to modify the source slightly so that it would take an array of FileSystemInfo[]