Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Showing windows (file/directory) context menu in c# winforms application

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

  • popup the context menu with some system call
  • read everything from the system context menu and insert it into my context menu

Could you please point me in the right direction? Thanks

like image 726
Axarydax Avatar asked Apr 06 '10 10:04

Axarydax


People also ask

How do I show the Windows context menu?

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.

What is Windows Explorer directory context menu?

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.

How do I add folders to the context menu?

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.

Where do I find context menu?

In Microsoft Windows, pressing the Application key or Shift+F10 opens a context menu for the region that has focus.


2 Answers

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.

like image 150
Grokys Avatar answered Oct 02 '22 10:10

Grokys


This may prove to be very challenging, so I propose two solutions:

  1. (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.

    enter image description here

  2. (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.

like image 25
Kevin McCormick Avatar answered Oct 02 '22 09:10

Kevin McCormick