Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9193811
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T21:15:15+00:00 2026-06-17T21:15:15+00:00

I am implementing a Webkit Browser control in my windows app. I need to

  • 0

I am implementing a Webkit Browser control in my windows app.

I need to use a custom context menu (right click) that only has copy/cut/paste as its options regardless of what element is right clicked. I need kind of a step-by-step as to how to implement it

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T21:15:16+00:00Added an answer on June 17, 2026 at 9:15 pm

    Customizing the context menu for the WebKitBrowser supposes that you get a reference to the WebViewClass and then, setting a IWebUIDelegate for it by calling the setUIDelegate() method.

    void MyWebBrowser_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
    {
        var webView = this.GetWebView() as WebKit.Interop.WebViewClass;
        webView.setUIDelegate(new MyWebUIDelegate(this));
    }
    

    In the IWebUIDelegate implementation you may intercept the contextMenuItemsForElement method and trigger the display of the context menu of the browser.

    Here is a working sample:

    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
    }
    

    For more insight, probably you would want to study some other customizations, such as open-webkit-sharp.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Implementing a custom membership provider, there are certain properties such as MinRequiredPasswordLength that only
Implementing a custom VM and I've come to use registers (these will store pointers
Im Implementing a video broadcasting website. For that I planned to use silverlight player
During implementing Menu control using jquery and css I got the following issue: Here
Implementing custom DataAnnotationsModelMetadataProvider in ASP.NET MVC2. Assuming the object that is being rendered looks
I`m implementing a custom filesystem on Ubuntu using Fuse, but I need to trap
Implementing a custom Dependency Property on a Framework Element object causes my Visual Studio
When implementing Serializable interface, in Java, we need to set it's serialVersionUID long. Is
when implementing a recursive function during development, i will use a counter and exit
Before implementing j_security_check using MySQL realm authentication in my web app. I had the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.