2012-07-26 85 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

相关问题