我试图通过webbrowser UIElement在PDF文件上禁用右键单击(以及上下文菜单)。但是不管它从未调用期望的处理程序(与加载普通html的webbrowser相同的行为,但不与其他UIElement一起使用)。通过Webbrowser在PDF查看器上禁用上下文菜单
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");
}
“上下文菜单PDF”行从不打印。我也尝试过使用MouseDown,但保持不变。
编辑1:感谢MephestoKhaan我设法通过网页浏览器使网站的工作。对于PDF,它应该是类似的东西,我仍然在寻找正确的类来投射Webbrowser.document对象。
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;
}
嗨,我可以知道如何使用FoxIt禁用所有菜单和右键单击事件吗?谢谢 – 2015-10-08 09:20:49