From c0d667fc7a482072bcca1ea37d8f99f7b1e3fda9 Mon Sep 17 00:00:00 2001 From: amaitland Date: Mon, 2 Jul 2018 19:43:42 +1000 Subject: [PATCH] WinForms - SetFocus to ChromiumWebBrowser when browser has initialized You can now type directly into the Google search box --- CefSharp.MinimalExample.WinForms/BrowserForm.cs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/CefSharp.MinimalExample.WinForms/BrowserForm.cs b/CefSharp.MinimalExample.WinForms/BrowserForm.cs index 1d6312d..4305333 100644 --- a/CefSharp.MinimalExample.WinForms/BrowserForm.cs +++ b/CefSharp.MinimalExample.WinForms/BrowserForm.cs @@ -26,6 +26,7 @@ namespace CefSharp.MinimalExample.WinForms }; toolStripContainer.ContentPanel.Controls.Add(browser); + browser.IsBrowserInitializedChanged += OnIsBrowserInitializedChanged; browser.LoadingStateChanged += OnLoadingStateChanged; browser.ConsoleMessage += OnBrowserConsoleMessage; browser.StatusMessage += OnBrowserStatusMessage; @@ -37,6 +38,16 @@ namespace CefSharp.MinimalExample.WinForms DisplayOutput(version); } + private void OnIsBrowserInitializedChanged(object sender, IsBrowserInitializedChangedEventArgs e) + { + if(e.IsBrowserInitialized) + { + var b = ((ChromiumWebBrowser)sender); + + this.InvokeOnUiThreadIfRequired(() => b.Focus()); + } + } + private void OnBrowserConsoleMessage(object sender, ConsoleMessageEventArgs args) { DisplayOutput(string.Format("Line: {0}, Source: {1}, Message: {2}", args.Line, args.Source, args.Message));