我正在尝试通过网络浏览器 UIElement 禁用 PDF 文件上的右键单击(以及上下文菜单)。但无论它永远不会调用所需的处理程序(与加载普通 html 的网络浏览器的行为相同,但与其他 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");
}
“CONTEXT MENU PDF”行从不打印。我也尝试过使用 MouseDown,但保持不变。
编辑 1:感谢 MephestoKhaan,我设法通过 webbrowser 与 Webs 一起工作。对于 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;
}