我試圖通過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