public bool OnContextMenuCommand(IWebBrowser browserControl, IBrowser browser, IFrame frame, IContextMenuParams parameters, CefMenuCommand commandId, CefEventFlags eventFlags) { switch (commandId) { case CefMenuCommand.Copy: //复制 var selectText = parameters.SelectionText; //获取选中的内容 frame.Copy(); break; case CefMenuCommand.Paste: //粘贴 frame.Paste(); break; case CefMenuCommand.Print: //打印 browser.Print(); break; } return(true); }
public bool OnContextMenuCommand(IWebBrowser browserControl, IBrowser browser, IFrame frame, IContextMenuParams parameters, CefMenuCommand commandId, CefEventFlags eventFlags) { if (commandId == CefMenuCommand.Back) { if (browser.CanGoBack) { browser.GoBack(); } return(true); } else if (commandId == CefMenuCommand.Forward) { if (browser.CanGoForward) { browser.GoForward(); } return(true); } else if (commandId == CefMenuCommand.Print) { browser.Print(); return(true); } else if (commandId == CefMenuCommand.ViewSource) { browserControl.ViewSource(); return(true); } else if (commandId == (CefMenuCommand)ContextMenuCommand.CMD_MY_COPY) // mycopy { _frmMain.last_command = ContextMenuCommand.CMD_MY_COPY; _frmMain.isCopyWithoutTranslate = true; string oldClipboard = Clipboard.GetText(); //browserControl.Copy(); //Application.DoEvents(); //_frmMain.isCopyWithoutTranslate = true; //frame.Copy(); short i = 0; while (i <= 8) { frame.Copy(); browserControl.ExecuteScriptAsync("document.execCommand(\"copy\");"); string tmpClipboard = Clipboard.GetText(); if (tmpClipboard != oldClipboard) { break; } Thread.Sleep(1); i++; } return(true); } else if (commandId == (CefMenuCommand)ContextMenuCommand.CMD_COPY) //copy { _frmMain.last_command = ContextMenuCommand.CMD_COPY; _frmMain.isCopyWithoutTranslate = false; //_browser.Copy(); frame.Copy(); //_frmMain.isCopyWithoutTranslate = false; return(true); } else { foreach (MenuBrowser l_menuBrowser in _lstMenuBrowser) { if ((CefMenuCommand)l_menuBrowser.Command == commandId) { _frmMain.last_command = l_menuBrowser.Command; _frmMain.isCopyWithoutTranslate = true; _browser.Copy(); return(true); } } } // Return false should ignore the selected option of the user ! //return false; return(true); }