I'm trying to display standard file/directory context menu in WinForms application - I'd like to enable the user to do things with files in my application as he could in Explorer.
There should be two options
Could you please point me in the right direction? Thanks
To open the context menu, right-click (or press and hold) on a file or folder in File Explorer. To find commands from the previous Windows 10 context menu: Right-click (or press and hold) on a file or folder to open the context menu. Select Show more options.
A context menu is a pop-up menu that provides shortcuts for actions the software developer anticipates the user might want to take. In a Windows environment, the context menu is accessed with a right mouse click.
To add a folder you access often to the context menu, select Folder in the Item type to add box. In the Program to add box, click Choose Folder. NOTE: You can also add files to the context menu. If you choose to add Any type of file, the Choose Folder button becomes the Search button.
In Microsoft Windows, pressing the Application key or Shift+F10 opens a context menu for the region that has focus.
I have written a .NET library to allow this. You can find it here:
http://gong-shell.sourceforge.net/
The class you're looking for is ShellContextMenu within that library.
This may prove to be very challenging, so I propose two solutions:
(Easy) Using the library that Groky suggested, do what is done in FolderSizes. The Explorer context menu is shown as a sub-context-menu. You can simulate this by displaying the explorer menu when the "Explorer Operation" item is hovered.
(Hard) If that is insufficient, you can go all the way and get the menu items from the shell, and create your own menu. This CodeProject article ( http://www.codeproject.com/KB/miscctrl/FileBrowser.aspx ) goes through the process of enumerating and invoking shell commands for a specific shell object, and how to enumerate submenus.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With