diff --git a/CefSharp.WinForms.Example/BrowserTabUserControl.cs b/CefSharp.WinForms.Example/BrowserTabUserControl.cs index 4698f17e28..10e07a3837 100644 --- a/CefSharp.WinForms.Example/BrowserTabUserControl.cs +++ b/CefSharp.WinForms.Example/BrowserTabUserControl.cs @@ -24,7 +24,7 @@ public BrowserTabUserControl(string url) Browser = browser; browser.MenuHandler = new MenuHandler(); - browser.FocusHandler = new FocusHandler(browser, urlTextBox); + //browser.FocusHandler = new FocusHandler(browser, urlTextBox); browser.NavStateChanged += OnBrowserNavStateChanged; browser.ConsoleMessage += OnBrowserConsoleMessage; browser.TitleChanged += OnBrowserTitleChanged; diff --git a/CefSharp.WinForms/ChromiumWebBrowser.cs b/CefSharp.WinForms/ChromiumWebBrowser.cs index 0eb8cb50cd..3ed8b452e2 100644 --- a/CefSharp.WinForms/ChromiumWebBrowser.cs +++ b/CefSharp.WinForms/ChromiumWebBrowser.cs @@ -55,6 +55,8 @@ public ChromiumWebBrowser(string address) Address = address; Dock = DockStyle.Fill; + + FocusHandler = new DefaultFocusHandler(this); } protected override void Dispose(bool disposing) @@ -354,5 +356,31 @@ private void ResizeBrowser() managedCefBrowserAdapter.Resize(Width, Height); } } + + #region DefaultFocusHandler + private class DefaultFocusHandler : IFocusHandler + { + private ChromiumWebBrowser browser; + + public DefaultFocusHandler(ChromiumWebBrowser browser) + { + this.browser = browser; + } + + public void OnGotFocus() + { + } + + public bool OnSetFocus(CefFocusSource source) + { + return false; + } + + public void OnTakeFocus(bool next) + { + browser.BeginInvoke(new MethodInvoker(() => browser.SelectNextControl(browser, next, true, true, true))); + } + } + #endregion } }