Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Customizing the context menu for the <code>WebKitBrowser</code> supposes that you get a reference to the <code>WebViewClass</code> and then, setting a <code>IWebUIDelegate</code> for it by calling the <code>setUIDelegate()</code> method.</p> <pre><code>void MyWebBrowser_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e) { var webView = this.GetWebView() as WebKit.Interop.WebViewClass; webView.setUIDelegate(new MyWebUIDelegate(this)); } </code></pre> <p>In the <code>IWebUIDelegate</code> implementation you may intercept the <code>contextMenuItemsForElement</code> method and trigger the display of the context menu of the browser.</p> <p>Here is a working sample:</p> <pre><code>public partial class Form1 : Form { MyWebBrowser webKitBrowser; public Form1() { InitializeComponent(); webKitBrowser = new MyWebBrowser(); webKitBrowser.Dock = DockStyle.Fill; this.Controls.Add(webKitBrowser); webKitBrowser.Navigate("http://www.google.com"); } } class MyContextMenu : ContextMenu { public MyContextMenu() { var cutMenuItem = new MenuItem("Cut"); var copyMenuItem = new MenuItem("Copy"); var pasteMenuItem = new MenuItem("Paste"); cutMenuItem.Click += cutMenuItem_Click; MenuItems.Add(cutMenuItem); MenuItems.Add(copyMenuItem); MenuItems.Add(pasteMenuItem); } void cutMenuItem_Click(object sender, EventArgs e) { //TODO: implement functionality MessageBox.Show("Cut was selected"); } } class MyWebBrowser : WebKitBrowser { public event EventHandler ShowContextMenu = new EventHandler(OnFireShowContextMenu); public MyWebBrowser() { DocumentCompleted += MyWebBrowser_DocumentCompleted; var myContextMenu = new MyContextMenu(); ContextMenu = myContextMenu; } void MyWebBrowser_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e) { var webView = this.GetWebView() as WebKit.Interop.WebViewClass; webView.setUIDelegate(new MyWebUIDelegate(this)); } public static void OnFireShowContextMenu(object sender, EventArgs e) { var webBrowser = (Control)sender; var webView = (WebKit.Interop.WebViewClass)((MyWebBrowser)sender).GetWebView(); var originalPoint = webBrowser.PointToScreen(new Point(0, 0)); var currentPoint = new Point(Cursor.Position.X - originalPoint.X, Cursor.Position.Y - originalPoint.Y); ((WebKitBrowser)sender).ContextMenu.Show((Control)sender, currentPoint); } public void FireShowContextMenu() { this.ShowContextMenu(this, null); } } class MyWebUIDelegate : IWebUIDelegate { private MyWebBrowser owner; public MyWebUIDelegate(MyWebBrowser browser) { this.owner = browser; } //trigger the browser's FireShowContextMenu() method public int contextMenuItemsForElement(WebView sender, CFDictionaryPropertyBag element, int defaultItemsHMenu) { owner.FireShowContextMenu(); return defaultItemsHMenu; } //return 1, true public int hasCustomMenuImplementation() { return 1; } //the rest of the IWebUIDelegate interface implementation } </code></pre> <p>For more insight, probably you would want to study some other customizations, such as <a href="https://code.google.com/p/open-webkit-sharp/" rel="nofollow">open-webkit-sharp</a>.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload