I am currently working on an Advanced text editor, and I was looking for a way to implement the Window's shell context menu in my code. I came across Andreas Johansson's WebLog which provided me with the answer. He took some of the code that Steven Roebert created and placed it in one file for ease of use. His code had several errors that were easily corrected, and now I am posting the finished product.
Using the Code
The code is pretty straightforward to use:
- Add the ShellContextMenu.cs file to your project.
- Create a new instance of the
- Call the
ShowContextMenu method with the proper arguments.
FileInfo/DirectoryInfo Array - A list of files/directories that need the Context Menu
Point - Point to Display Context Menu
ShellContextMenu ctxMnu = new ShellContextMenu();
FileInfo arrFI = new FileInfo;
arrFI = new FileInfo(this.treeMain.SelectedNode.Tag.ToString());
ctxMnu.ShowContextMenu(arrFI, this.PointToScreen(new Point(e.X, e.Y)));
- 12/10/07 - Created article
- 27/05/08 - Cleaned code a bit