It is hard to find on the internet a detailed and complete solution for modifying the contextual menu due to several reasons.
One of these reasons is that many of the implementations found use the System.Windows.Forms.ContextMenu; you can see one of them here:
Component-Based Development with Visual C#
In these kinds of examples the system menu is not invoked from the ShowContextMenu, instead a user customized menu is. This menu does not allow modifying it as we need.
Another reason is due to the programming language. In the MSDN website a C++ implementation of the ShowContextMenu can be found:
WebBrowser Customization (Part 2)
The problem is that when we want to implement it in C# difficulties such as not being able to call system functions, use the same data types, and many others arise.
Maybe the biggest difficulty can be found when trying to marshall the CComVariant class. A huge variety of solutions can be found on the internet, but they usually do not work (at least in the case mentioned above). Here are some examples of them:
What is the equivalent of Variant data type in C#.NET?
Using the int[] type with size 3 or bigger is one of the ways of solving this.
1: int[] variantVar = new int[3];
The VARIANT type can be seen in this MSDN webpage:
Once we solved this problem, we can use the IOleCommandTarget function Exec:
1: [PreserveSig]
2: int Exec(
3: ref Guid pguidCmdGroup,
4: int nCmdID,
5: int nCmdExecOpt,
6: // we need to have this an array because callers
7: // need to be able to specify NULL or VT_NULL
8: [In, MarshalAs(UnmanagedType.LPArray)] int[] pvaIn,
9: [Out, MarshalAs(UnmanagedType.LPArray)] int[] pvaOut
10: );
When calling Exec for the first time, we get the handle for the language submenu. We obtain it in variantVar variable:
1: int[] nullVariantVar = null;
2: int[] variantVar = new int[3];
3:
4: spCT.Exec(
5: ref CGID_ShellDocView,
6: SHDVID_GETMIMECSETMENU,
7: 0,
8: nullVariantVar,
9: variantVar
10: );
Now we must parse variantVar in order to get the result (the handle for the language submenu). The first value that we get is a VARTYPE type, which indicates the kind of variable that we will find next. Then there is a reserved spot of three WORD long, followed by the value we are looking for. So the handle for the submenu is on the second place of the array:
1: IntPtr handleSubMenu = new IntPtr(variantVar[2]);
We can replace passing the CComVariant argument to the function by creating a new variable shown in the code below and then call again Exec:
1: variantVarIn[0] = VT_INT_PTR;
2: // Remember that variantVarIn[1] is reserved
3: variantVarIn[2] = handleMenu.ToInt32();
4:
5: variantVarOut[0] = VT_I4;
6: // Remember that variantVarOut[1] is reserved
7: variantVarOut[2] = dwID;
8:
9: // Insert Shortcut Menu Extensions from registry.
10: spCT.Exec(
11: ref CGID_ShellDocView,
12: SHDVID_ADDMENUEXTENSIONS,
13: 0,
14: variantVarIn,
15: variantVarOut
16: );
We obtain the complete context menu as a result of the instructions shown above. This menu can be modified as much as we desire. Using this, you can add or remove menu items and also their functionality. For example you can call methods implemented in your project from the desired menu item.
Now you can build a customized browser using C# !

Kevin | 04-Mar-09 at 3:49 am | Permalink
It took me some time to find a solution to modifying the context menu in the webbrowser control using C#. It seems you may have what I need, however I have no idea to implement it. What’s the next step? How do I actually do what I need to do? I want to eliminate everything except Copy, Cut and Paste, when interacting text in HTML form elements. Can you help me?
Robert | 10-Aug-09 at 2:19 pm | Permalink
I have the same issue as Kevin. I have seen several ways of doing this but no one has actually posted complete samples of how to implement this.
JP | 24-Sep-09 at 9:20 pm | Permalink
Yes an actual demonstation of chopping up the webbrowser context menu would be greatly appreciated.
Kimberley25 | 27-Dec-09 at 3:45 pm | Permalink
I do not know if you trust me, thus, I really can apprise your good enough notes about this topic. Before this I took the aid at freelance writer .
mortgage loans | 28-Mar-10 at 8:27 pm | Permalink
One understands that humen’s life is not cheap, however we require cash for different things and not every man earns big sums cash. So to get good credit loans and term loan will be good solution.
Weight Loss Resource | 31-Mar-10 at 4:57 am | Permalink
I think it is good service! thanks
Aleksandr | 29-Apr-10 at 4:43 pm | Permalink
”Let no debt remain outstanding, except the continuing debt to love one another, for he who loves his fellowman has fulfilled the law.”- Romans 13:8
Aleks | 06-May-10 at 6:28 pm | Permalink
I wanted to thank you for this great read!! I definitely enjoying every little bit of it.It is a great website and nice share.I want to thank you.Good job! You guys do a great blog, and have some great contents. Keep up the good work.
teethman | 01-Jun-10 at 2:59 am | Permalink
This is my first time i visit here. I found so many interesting stuff in your blog especially its discussion. teeth whitening From the tons of comments on your articles, I guess I am not the only one having all the enjoyment here! keep up the good work.