How do you show the Windows Explorer context menu from a C# application?

后端 未结 3 1273
南笙
南笙 2020-12-04 22:48

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

3条回答
  •  渐次进展
    2020-12-04 23:40

    I found a great Code Project article that encapsulates everything very nicely into one class!

    Explorer Shell Context Menu

    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[]

提交回复
热议问题