adding an item to context menu
-
dear fellows i hope u will all be fine it is my first question on any forum. so i do not know how to put a question and how to get an answer.although i have read the instructions of how to get the answer yet i m not sure.. so at least one person answer my question. i want to add a menu item which should display in the menu when user right click on a file and some when user will point to this menu item. some other options to be shown. how to do this.pl help me (by sending code) or some reference material or help topic. waiting for your kind response A.Nadeem
-
dear fellows i hope u will all be fine it is my first question on any forum. so i do not know how to put a question and how to get an answer.although i have read the instructions of how to get the answer yet i m not sure.. so at least one person answer my question. i want to add a menu item which should display in the menu when user right click on a file and some when user will point to this menu item. some other options to be shown. how to do this.pl help me (by sending code) or some reference material or help topic. waiting for your kind response A.Nadeem
Hi, I'm not sure what your question is. If you are creating a program (in C# as implied by this forum) then you want to use the ContextMenu.Popup event to clear, then populate your context menu with items that depend on the item for which context is requested. Code would include things such as:
// once, probably in constructor
contextMenu.Popup+=new System.EventHandler(myPopup);// event handler
private void myPopup(object sender, EventArgs e) {
Menu menu=sender as Menu;
menu.MenuItems.Clear();
mi=addMenuItem(menu, "Copy File", new EventHandler(CopyFileHandler));
mi.Enabled=LongNameIsFileSpec;
mi=addMenuItem(menu, "Explore", new EventHandler(ExploreHandler));
mi.Enabled=LongNameIsFileSpec;
...
}protected MenuItem addMenuItem(Menu menu, string text, EventHandler handler) {
return addMenuItem(menu, text, Shortcut.None, handler);
}protected MenuItem addMenuItem(Menu menu, string text, Shortcut sc,
EventHandler handler) {
MenuItem menuItem=new MenuItem(text);
menuItem.Click+=handler;
menuItem.Shortcut=sc;
menu.MenuItems.Add(menuItem);
menuItem.Enabled=handler!=null;
return menuItem;
}If you are referring to the context menu presented by Windows Explorer, there are basically two ways to add user defined menu items: - you can add an item for all files, all folders, or all files+folders by creating the right entries in the System's Registry - you can have Explorer start a small user-provided program to dynamically add one or more context menu items very time something gets right clicked. Hope this helps. :)
Luc Pattyn [My Articles]
-
Hi, I'm not sure what your question is. If you are creating a program (in C# as implied by this forum) then you want to use the ContextMenu.Popup event to clear, then populate your context menu with items that depend on the item for which context is requested. Code would include things such as:
// once, probably in constructor
contextMenu.Popup+=new System.EventHandler(myPopup);// event handler
private void myPopup(object sender, EventArgs e) {
Menu menu=sender as Menu;
menu.MenuItems.Clear();
mi=addMenuItem(menu, "Copy File", new EventHandler(CopyFileHandler));
mi.Enabled=LongNameIsFileSpec;
mi=addMenuItem(menu, "Explore", new EventHandler(ExploreHandler));
mi.Enabled=LongNameIsFileSpec;
...
}protected MenuItem addMenuItem(Menu menu, string text, EventHandler handler) {
return addMenuItem(menu, text, Shortcut.None, handler);
}protected MenuItem addMenuItem(Menu menu, string text, Shortcut sc,
EventHandler handler) {
MenuItem menuItem=new MenuItem(text);
menuItem.Click+=handler;
menuItem.Shortcut=sc;
menu.MenuItems.Add(menuItem);
menuItem.Enabled=handler!=null;
return menuItem;
}If you are referring to the context menu presented by Windows Explorer, there are basically two ways to add user defined menu items: - you can add an item for all files, all folders, or all files+folders by creating the right entries in the System's Registry - you can have Explorer start a small user-provided program to dynamically add one or more context menu items very time something gets right clicked. Hope this helps. :)
Luc Pattyn [My Articles]
Hi i was referring to context menu presented by windows explorer and i want to show it against all files and folders. so how to write enteries to registery... what enteries and where(in the registery)... waiting for your reply. thanks in advance
-
Hi i was referring to context menu presented by windows explorer and i want to show it against all files and folders. so how to write enteries to registery... what enteries and where(in the registery)... waiting for your reply. thanks in advance
-
Hi i was referring to context menu presented by windows explorer and i want to show it against all files and folders. so how to write enteries to registery... what enteries and where(in the registery)... waiting for your reply. thanks in advance
Hi, this is how I do it: - I have my program contain a menu item to install itself as a possible tool to open all files and folders - when that menu item is clicked, it creates two registry entries: HKEY_CLASSES_ROOT\AllFilesystemObjects\Shell\myProgName.ContextMenu (Default)=text to show in context menu HKEY_CLASSES_ROOT\AllFilesystemObjects\Shell\myProgName.ContextMenu\Command (Default)=myProgPath %1 myProgPath can be obtained as Environment.GetCommandLineArgs()[0] %1 means append the file/folder selected, and will result in a command line arg For manipulating the registry, I use P/Invoke to OpenKey, CloseKey, and RegSetValueEx since I want my code to also work under .NET 1.x; but starting with 2.0 there are easier ways to do it. BTW the (Default) key is accessed with name=null. :)
Luc Pattyn [My Articles]