仅允许在 System.Windows.Forms.WebBrowser 控件中复制/粘贴上下文菜单
WebBrowser 控件有一个名为“IsWebBrowserContextMenuEnabled”的属性,该属性禁用在网页上右键单击并查看上下文菜单的所有功能。 这非常接近我想要的(我不希望任何人能够右键单击并打印、回击、点击属性、查看源代码等)。
唯一的问题是,这也会禁用文本框中出现的用于复制/粘贴等的上下文菜单。
我想禁用主上下文菜单,但允许出现的菜单在文本框中。 有人知道我会怎么做吗? WebBrowser.Document.ContextMenuShowing 事件看起来很有希望,但似乎无法通过 HtmlElementEventArgs 参数的“FromElement”和“ToElement”属性正确识别用户右键单击的元素,发送者也不是除了 HtmlDocument 之外的任何内容元素。
提前致谢!
The WebBrowser control has a property called "IsWebBrowserContextMenuEnabled" that disables all ability to right-click on a web page and see a context menu. This is very close to what I want (I don't want anyone to be able to right-click and print, hit back, hit properties, view source, etc).
The only problem is this also disables the context menu that appears in TextBoxes for copy/paste, etc.
To make this clearer, this is what I don't want:
I would like to disable the main context menu, but allow the one that appears in TextBoxes. Anyone know how I would do that? The WebBrowser.Document.ContextMenuShowing event looks promising, but doesn't seem to properly identify the element the user is right-clicking on, either through the HtmlElementEventArgs parameter's "FromElement" and "ToElement" properties, nor is the sender anything but the HtmlDocument element.
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您是否考虑过用 JavaScript 编写自己的上下文菜单? 只需听用户右键单击正文,然后使用复制和粘贴命令显示菜单(提示:element.style.display =“block|none”)。 要复制,请执行以下代码:
并粘贴:
源:
http://www.geekpedia.com/tutorial126_Clipboard-cut-copy-and-paste-with-JavaScript.html
注意:这仅适用于 IE(这适合您的应用程序)。
我知道它无论如何都不是防弹的,但这里有一个代码示例可以帮助您入门:
have you considered writing your own context menu in javascript? Just listen to the user right clicking on the body, then show your menu with copy and paste commands (hint: element.style.display = "block|none"). To copy, execute the following code:
And to paste:
Source:
http://www.geekpedia.com/tutorial126_Clipboard-cut-copy-and-paste-with-JavaScript.html
NOTE: This only works in IE (which is fine for your application).
I know its not bulletproof by any means, but here is a code sample that should get you started:
我希望这对你有帮助 安德森·伊姆斯
I hope this will help you Anderson Imes
快速浏览一下 MSDN 文档 显示您的程序不支持使用任何鼠标事件(单击、按钮向下/向上等)。 恐怕要么是:要么禁用 conetxt 菜单,要么允许它们。
如果禁用它们,用户仍然可以复制和复制它们。 使用键盘快捷键(Ctrl-C、Ctrl-V)粘贴。 也许这给了你你需要的功能。
A quick look at the MSDN documentation shows that none of the mouse events (click, button down/up etc) are supported to be used in your program. I'm afraid its either or: Either disable conetxt menus, or allow them.
If you disable them, the user can still copy & paste using keyboard shortcuts (Ctrl-C, Ctrl-V). Maybe that gives you the functionality you need.
我们最终使用了上述两种评论的组合。 更接近第二个,这就是我给他信任的原因。
有一种方法可以在客户端 Web 代码上以及通过 winforms 替换上下文菜单,这就是我们采用的方法。 我真的不想重写上下文菜单,但这似乎给了我们正确的控制组合。
We ended up using a combination of both of the above comments. Closer to the second, which is why I gave him credit.
There is a way to replace the context menu on both the client-side web code as well as through winforms, which is the approach we took. I really didn't want to rewrite the context menu, but this seems to have given us the right mix of control.