需要禁用ChromiumWebBrowser右键单击VB .Net中的上下文菜单.
我尝试了许多来自官方文档的代码示例,并将代码从C转换为VB,但仍然无法使其工作。
请向我展示一些示例代码,以禁用右击,并避免vb .Net中的拖放.Net。
类文件
Public Class CustomMenuHandler
Public Sub OnBeforeContextMenu(ByVal browserControl As IWebBrowser, ByVal browser As CefSharp.IBrowser, ByVal frame As IFrame, ByVal parameters As IContextMenuParams, ByVal model As IMenuModel)
model.Clear()
End Sub
Public Function OnContextMenuCommand(ByVal browserControl As IWebBrowser, ByVal browser As CefSharp.IBrowser, ByVal frame As IFrame, ByVal parameters As IContextMenuParams, ByVal commandId As CefMenuCommand, ByVal eventFlags As CefEventFlags) As Boolean
Return False
End Function
Public Sub OnContextMenuDismissed(ByVal browserControl As IWebBrowser, ByVal browser As CefSharp.IBrowser, ByVal frame As IFrame)
End Sub
End Class
呼叫类
browser = New ChromiumWebBrowser("google.com")
browser.MenuHandler = New CustomMenuHandler
panel1.Controls.Add(browser)
'CefSharp.IContextMenuHandler'.错误:附加信息:“Project.CustomMenuHandler”类型的对象不能转换为
类型
发布于 2020-05-03 18:14:25
这是我在社会上的第一次回答或回答。
我找了好几个小时,找到了一个解决办法
所以您希望首先实现IContextMenuHandler
之后,您希望在每个函数之后实现IContextMenuHandler。
Imports System
Imports CefSharp
Imports System.Windows.Forms
Public Class MyCustomMenuHandler
Implements IContextMenuHandler
Public Sub OnBeforeContextMenu(ByVal browserControl As IWebBrowser, ByVal browser As IBrowser, ByVal frame As IFrame, ByVal parameters As IContextMenuParams, ByVal model As IMenuModel) Implements IContextMenuHandler.OnBeforeContextMenu
model.Clear()
End Sub
Public Function OnContextMenuCommand(ByVal browserControl As IWebBrowser, ByVal browser As IBrowser, ByVal frame As IFrame, ByVal parameters As IContextMenuParams, ByVal commandId As CefMenuCommand, ByVal eventFlags As CefEventFlags) As Boolean Implements IContextMenuHandler.OnContextMenuCommand
Return False
End Function
Public Sub OnContextMenuDismissed(ByVal browserControl As IWebBrowser, ByVal browser As IBrowser, ByVal frame As IFrame) Implements IContextMenuHandler.OnContextMenuDismissed
End Sub
Public Function RunContextMenu(ByVal browserControl As IWebBrowser, ByVal browser As IBrowser, ByVal frame As IFrame, ByVal parameters As IContextMenuParams, ByVal model As IMenuModel, ByVal callback As IRunContextMenuCallback) As Boolean Implements IContextMenuHandler.RunContextMenu
Return False
End Function
End Class
发布于 2019-10-27 00:08:32
首先,您的CustomMenuHandler
类应该实现所需的接口,如下所示:
Public Class CustomMenuHandler implements IContextMenuHandler
这能帮你解决这个问题。如果您正在寻找替代方案,您可以简单地捕获MouseDown
事件,检查鼠标中按下的键是否为鼠标右键(MouseButton.Right
),并使用e.Handled = True
处理单击事件;
希望这能帮上忙。
发布于 2020-09-08 15:04:28
这是正确的解决办法。用Browser.MenuHandler = New CustomMenuHandler()
来调用它
Imports System
Imports CefSharp
Imports System.Windows.Forms
Public Class CustomMenuHandler
Implements CefSharp.IContextMenuHandler
Public Sub OnBeforeContextMenu(ByVal browserControl As IWebBrowser, ByVal browser As IBrowser, ByVal frame As IFrame, ByVal parameters As IContextMenuParams, ByVal model As IMenuModel) Implements IContextMenuHandler.OnBeforeContextMenu
model.Clear()
End Sub
Public Function OnContextMenuCommand(ByVal browserControl As IWebBrowser, ByVal browser As IBrowser, ByVal frame As IFrame, ByVal parameters As IContextMenuParams, ByVal commandId As CefMenuCommand, ByVal eventFlags As CefEventFlags) As Boolean Implements IContextMenuHandler.OnContextMenuCommand
Return False
End Function
Public Sub OnContextMenuDismissed(ByVal browserControl As IWebBrowser, ByVal browser As IBrowser, ByVal frame As IFrame) Implements IContextMenuHandler.OnContextMenuDismissed
End Sub
Public Function RunContextMenu(ByVal browserControl As IWebBrowser, ByVal browser As IBrowser, ByVal frame As IFrame, ByVal parameters As IContextMenuParams, ByVal model As IMenuModel, ByVal callback As IRunContextMenuCallback) As Boolean Implements IContextMenuHandler.RunContextMenu
Return False
End Function
End Class
https://stackoverflow.com/questions/58574456
复制相似问题