Search code examples
c#winformspinvokechromium-embedded

CefWebBrowser and ProcessCmdKey of form


I have own form with modified ProcessCmdKey:

private class MyForm : Form
{
    protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
    {
        if (keyData == (Keys.Escape))
        {
            this.BeginInvoke((MethodInvoker)delegate { this.Close(); }); 
            return true;     
        }
        return base.ProcessCmdKey(ref msg, keyData);
    }
}

On this form I have a panel:

this._panel.BorderStyle = System.Windows.Forms.BorderStyle.None;
this._form.Controls.Add(this._panel);
this._panel.Parent = this._form;
this._panel.Size = this._form.Size;

On this panel I've browser control:

this._Chrome = new Xilium.CefGlue.WindowsForms.CefWebBrowser();
this._Chrome.StartUrl = "google.ru";
this._Chrome.Parent = this._panel;
this._Chrome.Dock = DockStyle.Fill;
this._Chrome.BringToFront();

1. Why ESCAPE key doesn't work?

2. How to disable in CefWebBrowser popup menu and disable follow link?


Solution

  • You can intercept any key input from native window, and pass needed keys to browser via CefBrowserHost.SendKeyEvent.