Web 浏览器控件 - 防止右键单击

发布于 2024-10-09 02:48:25 字数 105 浏览 0 评论 0原文

在我的应用程序中,我有一个包含浏览器控件的表单,我在其中显示 SSRS 报告。我想阻止用户右键单击浏览器控件并显示弹出菜单。理想情况下,我希望右键单击不执行任何操作。有什么方法可以实现这个目标吗?

In my application, I have a form that contains a browser control in which I display an SSRS report. I would like to prevent the user from right-clicking in the browser control and being shown the popup menu. Ideally I'd like the right-click to do nothing. Is there a way I can accomplish this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

未央 2024-10-16 02:48:25

您可以将 IsWebBrowserContextMenuEnabled 设置为 false。您可能还想将AllowWebBrowserDrop 设置为 false,这样他们就无法将网址拖到应用程序中并加载它。

        webBrowser1.IsWebBrowserContextMenuEnabled = false;
        webBrowser1.AllowWebBrowserDrop = false;

You can set the IsWebBrowserContextMenuEnabled equal to false. You will probably also want to set AllowWebBrowserDrop equal to false too so they cant drag a url into the app and have it load.

        webBrowser1.IsWebBrowserContextMenuEnabled = false;
        webBrowser1.AllowWebBrowserDrop = false;
迷途知返 2024-10-16 02:48:25

对于任何情况,winform 或 wpf:

     private void WebBrowser_LoadCompleted(object sender, System.Windows.Navigation.NavigationEventArgs e)
        {
            ((WebBrowser)sender).InvokeScript("eval", "$(document).contextmenu(function() {    return false;        });");
}

for any case, winform or wpf:

     private void WebBrowser_LoadCompleted(object sender, System.Windows.Navigation.NavigationEventArgs e)
        {
            ((WebBrowser)sender).InvokeScript("eval", "$(document).contextmenu(function() {    return false;        });");
}
淡忘如思 2024-10-16 02:48:25

对于WPF ===>

wbBrowser.ContextMenu.IsEnabled = false;

For WPF ===>

wbBrowser.ContextMenu.IsEnabled = false;

两相知 2024-10-16 02:48:25

IsWebBrowserContextMenuEnabled 属性设置为 false

Set the IsWebBrowserContextMenuEnabled property to false.

逆夏时光 2024-10-16 02:48:25

我的项目(WPF - MVVM)有一个解决方案:

重要添加参考:Microsoft.mshtml

实现事件:webBrowser.LoadCompleted += webBrowser_LoadCompleted;

using mshtml;

private void webBrowser_LoadCompleted(object sender, System.Windows.Navigation.NavigationEventArgs e)
{
    object doc = webBrowser.Document;
    HTMLDocumentEvents2_Event evn2 = doc as HTMLDocumentEvents2_Event;
    HTMLDocumentEvents_Event evn = doc as HTMLDocumentEvents_Event;
    evn.oncontextmenu += new HTMLDocumentEvents_oncontextmenuEventHandler(Evn_oncontextmenu);
    evn2.oncontextmenu += new HTMLDocumentEvents2_oncontextmenuEventHandler(Evn2_oncontextmenu);
}

private bool Evn2_oncontextmenu(IHTMLEventObj pEvtObj)
{
    return false;
}

private bool Evn_oncontextmenu()
{
    return false;
}

希望有帮助。

I have a solution work on my project (WPF - MVVM):

Important add reference: Microsoft.mshtml

Implement event: webBrowser.LoadCompleted += webBrowser_LoadCompleted;

using mshtml;

private void webBrowser_LoadCompleted(object sender, System.Windows.Navigation.NavigationEventArgs e)
{
    object doc = webBrowser.Document;
    HTMLDocumentEvents2_Event evn2 = doc as HTMLDocumentEvents2_Event;
    HTMLDocumentEvents_Event evn = doc as HTMLDocumentEvents_Event;
    evn.oncontextmenu += new HTMLDocumentEvents_oncontextmenuEventHandler(Evn_oncontextmenu);
    evn2.oncontextmenu += new HTMLDocumentEvents2_oncontextmenuEventHandler(Evn2_oncontextmenu);
}

private bool Evn2_oncontextmenu(IHTMLEventObj pEvtObj)
{
    return false;
}

private bool Evn_oncontextmenu()
{
    return false;
}

Hope helpful.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文