2012-07-26 59 views
0

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

回答

1

好,MephestoKhaan的是正確的方式爲網絡瀏覽器上的元素(例如:網頁),但在通過Webbrowser通過Webbrowser掙扎之後,我更改爲福昕閱讀器。

使用Foxit我可以禁用所有菜單並右鍵單擊事件,並直接在全屏打開(不是網頁瀏覽器,而是另一個窗口),它不完全是wh在我問,但解決了我最直接的問題(在PDF瀏覽器上沒有上下文菜單)。

對於記錄>如果您希望在窗口上有按鈕或某個自定義界面,請使用Popup並將窗口設置爲一切。

+0

嗨,我可以知道如何使用FoxIt禁用所有菜單和右鍵單擊事件嗎?謝謝 – 2015-10-08 09:20:49