C# webbrowser控件,更改右键单击选项
我需要你的帮助来在我拥有的网络浏览器控件中创建右键单击选项。 如果我右键单击链接,可能会打开此选项: 在新选项卡中打开 在新窗口中打开 复制链接 请帮助我创建 C# 代码和解释,因为我是网络浏览器控制的新手。
i need your help to create a right click option in webbrowser control i have.
may be if i right click in a link will open this option :
open in new tab
open in new window
copy link
please help me create a the C# code and the explaination, because i am a newbie in webbrowser control.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用 Visual Studio 创建您自己的上下文菜单非常容易。只需将一个上下文菜单项放到您的表单上,然后繁荣,您就快完成了。
添加所需的按钮,根据需要处理其单击/更改事件。
然后,在您的代码中,要么使用 webBrowser 控件上的属性将上下文菜单更改为您创建的菜单,要么在 Form_Load 上的代码中处理它。
browserCMenu 将在设计器内部创建,但您也可以从代码创建:
请注意,上面是设计器生成的代码。由于您(很可能)将使用 Visual Studio 设计器来完成工作,因此您只需执行以下步骤:
您还可以查询目标文本类型,但我不会在这里详细介绍,您可以搜索 MSDN 来获取该信息,或者在 StackOverflow 上搜索,有几篇相关文章。但这将允许您右键单击不同类型的数据获得不同的上下文菜单(我个人认为它没有什么用处)。最好为所有使用相同上下文菜单项的浏览器控件提供一个标准上下文菜单,这样您的代码就不会因上下文菜单过多而陷入困境/过于复杂。
It's pretty easy to create your own context menu using Visual studio. Just drop a context menu item onto your form, and boom, your almost done.
Add the buttons you want, handle their click/changed events as necessary.
Then, in your code, either use the properties on the webBrowser control to change the context menu to the one you created, or handle it in code on Form_Load.
Where browserCMenu would be created inside of the designer, but you could create from code as well:
Note that the above is designer generated code. As you'll be (most likely) using the Visual Studio designer to do your work you can just do the following steps:
You can also query what type of text is being targeted as well, but i wont go into that here, you can search MSDN for that information, or search here on StackOverflow, there are several articles on that. But that will allow you to obtain different context menus for different types of data being right clicked (i dont find it that useful personally). It's best just to present a standard context menu for all browser controls, that use the same context menu items, so that your code isn't bogged down/too complex with too many context menus.