I'm trying to disable the right click(well context menu) on a PDF file over a webbrowser UIElement. But no matter what it never calls to the desired handler (same behavior with a webbrowser loading usual html, but not with other UIElements).
public override UIElement Play()
{
base.Play();
//It will be represented in a Webbrowser element
WebBrowser element = new WebBrowser();
element.ContextMenuOpening +=new ContextMenuEventHandler(element_ContextMenuOpening);
//navigate to the current path of the file in the HDD, adding some parameters to avoid the Adobe Reader pannels to be shown
element.Source = new Uri(path+"#toolbar=0&navpanes=0");
return element;
}
public void element_ContextMenuOpening(Object obj, ContextMenuEventArgs e)
{
Console.WriteLine("CONTEXT MENU PDF");
}
The "CONTEXT MENU PDF" line is never printed. I have also tried with MouseDown, but remains the same.
EDIT 1: Thanks to MephestoKhaan I managed to make this work with Webs over webbrowser. For PDF it should be something similar and I'm still looking for the correct class to cast the Webbrowser.document object to.
public override UIElement Play()
{
base.Play();
//the element will be represented in a webbroser
element = new WebBrowser();
//load the web indicated by the path (url)
element.NavigateToString(Path);
element.Source = new Uri(Path);
//disable context menu
mshtml.HTMLDocumentEvents2_Event iEvent;
iEvent = (mshtml.HTMLDocumentEvents2_Event) element.Document;
iEvent.oncontextmenu += new mshtml.HTMLDocumentEvents2_oncontextmenuEventHandler(iEvent_oncontextmenu);
return element;
}
bool iEvent_oncontextmenu(mshtml.IHTMLEventObj e)
{
return false;
}