I am using an EventHandler to suppress a context menu on an AxWebBrowser. I am using the code below:
public class HtmlEditor : System.Windows.Forms.UserControl
{
...
...
private AxSHDocVw.AxWebBrowser axWebBrowser1;
...
...
public HtmlEditor()
{
InitializeComponent();
axWebBrowser1.DocumentComplete +=new AxSHDocVw.DWebBrowserEvents2_DocumentCompleteEventHandler(axWebBrowser1_DocumentComplete);
axWebBrowser1.Navigate("about:blank");
axWebBrowser1.BeforeNavigate2 +=new AxSHDocVw.DWebBrowserEvents2_BeforeNavigate2EventHandler(axWebBrowser1_BeforeNavigate2);
mshtml.HTMLDocumentClass doc = (mshtml.HTMLDocumentClass)this.axWebBrowser1.Document;///stop here
doc.designMode = "On"; // This turns the control into an editor ///stop here
((mshtml.HTMLDocumentEvents2_Event)this.axWebBrowser1.Document).oncontextmenu += new mshtml.HTMLDocumentEvents2_oncontextmenuEventHandler(HtmlEditor_oncontextmenu); //suppress context menu ///stop here
Dirty = false;///stop here
}
private bool HtmlEditor_oncontextmenu(mshtml.IHTMLEventObj e)
{
return false;
}
...
...
}
There are four lines with the comment "///stop here". If I set a breakpoint at any one of those lines, run the app, then continue after I stop at that line, then the context menu does not appear when I right-click the control. However, if I put a breakpoint anywhere else and do the same, the context menu appears. Additionally, if I run the app with no breakpoints, the context menu appears.
I have also tried to assign the EventHandler in a separate method, called long after everything above is done executing, but again, the context menu appears.
Anyone have an idea how I can figure out my problem?