问题
Alright so I have this code in my program to add menu items in context menu and perform action when they are clicked
Private Sub IContextMenuHandler_OnBeforeContextMenu(browserControl As IWebBrowser, browser As IBrowser, frame As IFrame, parameters As IContextMenuParams, model As IMenuModel) Implements IContextMenuHandler.OnBeforeContextMenu
''Add new custom menu items
model.AddItem(DirectCast(Copy, CefMenuCommand), "Copy Link Address")
model.AddItem(CType(26504, CefMenuCommand), "Display alert message")
Dim viewMenu As IMenuModel = model.AddSubMenu(CType(26505, CefMenuCommand), "View")
viewMenu.AddRadioItem(CType(26506, CefMenuCommand), "Large icons", 0)
viewMenu.AddRadioItem(CType(26507, CefMenuCommand), "Medium icons", 0)
viewMenu.AddRadioItem(CType(26508, CefMenuCommand), "Small icons", 0)
viewMenu.AddSeparator()
End Sub
Private Function IContextMenuHandler_OnContextMenuCommand(browserControl As IWebBrowser, browser As IBrowser, frame As IFrame, parameters As IContextMenuParams, commandId As CefMenuCommand, eventFlags As CefEventFlags) As Boolean Implements IContextMenuHandler.OnContextMenuCommand
Try
If CInt(commandId) = Copy Then
If (parameters.LinkUrl.Length > 0) Then
Clipboard.SetText(parameters.LinkUrl)
End If
End If
If commandId = CType(26504, CefMenuCommand) Then
Clipboard.SetText(imn.GetLabel(CType(26504, CefMenuCommand)))
browserControl.Paste()
End If
Catch ex As Exception
''MsgBox(ex.Message)
End Try
Return False
End Function
How do I get the label of the menu item (in Oncontextmenucommand function) which was clicked ? How do I access the IMenuModel because it has a getlabel function.
Regards,
来源:https://stackoverflow.com/questions/49251796/cefsharp-oncontextmenucommand-get-menu-label