protected override void OnBeforeContextMenu(CefBrowser browser, CefFrame frame, CefContextMenuParams menuParams, CefMenuModel model) { var count = model.Count; if (count > 0) { for (int i = 0; i < count; i++) { var commandId = (CefMenuId)model.GetCommandIdAt(i); switch (commandId) { case CefMenuId.Undo: case CefMenuId.Redo: case CefMenuId.Cut: case CefMenuId.Copy: case CefMenuId.Paste: case CefMenuId.Delete: case CefMenuId.SelectAll: case CefMenuId.Find: break; default: break; } } } if (AppHelper.EnableDevtools) { model.Remove((int)CefMenuId.Print); model.Remove((int)CefMenuId.ViewSource); if (model.Count >= 1) { model.RemoveAt(model.Count - 1); } model.AddItem(SHOW_DEV_TOOLS, "&Show DevTools"); } else { model.Clear(); // 禁用右键菜单 } //model.InsertItemAt(model.Count > 0 ? 1 : 0, (int)CefMenuId.ReloadNocache, "Refresh"); //model.AddSeparator(); //model.AddItem(SHOW_DEV_TOOLS, "&Show DevTools"); //model.AddItem(INSPECT_ELEMENT, "Inspect element"); //CefMenuModel submenu = model.AddSubMenu(0, "Submenu Test"); //submenu.AddItem((int)CefMenuId.Copy, "Copy"); //submenu.AddItem((int)CefMenuId.Paste, "Paste"); //submenu.SetColorAt(submenu.Count - 1, CefMenuColorType.Text, CefColor.FromArgb((int)Colors.Blue.ToUint32())); //submenu.AddCheckItem(0, "Checked Test"); //submenu.SetCheckedAt(submenu.Count - 1, true); //submenu.AddRadioItem(0, "Radio Off", 0); //submenu.AddRadioItem(0, "Radio On", 1); //submenu.SetCheckedAt(submenu.Count - 1, true); }
/// <summary> /// The on before context menu. /// </summary> /// <param name="browser"> /// The browser. /// </param> /// <param name="frame"> /// The frame. /// </param> /// <param name="state"> /// The state. /// </param> /// <param name="model"> /// The model. /// </param> protected override void OnBeforeContextMenu(CefBrowser browser, CefFrame frame, CefContextMenuParams state, CefMenuModel model) { base.OnBeforeContextMenu(browser, frame, state, model); for (int x = model.Count - 1; x > -1; x--) { var item = model.GetLabelAt(x); if (item == "&Back" || item == "&Forward" || item == "&Print…" || item == "&View page source") { model.RemoveAt(x); } } if (model.Count == 1 && model.GetItemTypeAt(0).ToString() == "Separator") { model.RemoveAt(0); } model.AddItem((int)(CefMenuId)ShowDevTools, "Show DevTools"); model.AddItem((int)(CefMenuId)Refresh, "Refresh"); }