using System.Windows.Forms; using Cbdx.Tests.CefRelated; using Cbdx.Tests.Services; using CefSharp; using CefSharp.WinForms; namespace Cbdx.Tests { public partial class TestForm : Form { private readonly DataExchangeDispatcherBuilder _dataExchange; private ChromiumWebBrowser _browser; public TestForm() { InitializeComponent(); _dataExchange = new DataExchangeDispatcherBuilder(); _dataExchange.RegisterService(new WindowControlService(this)); } private void DemoForm_Shown(object sender, System.EventArgs e) { CreateOrReloadCefBrowserControl(); } public void CreateOrReloadCefBrowserControl() { if (null != _browser) { MainPanel.Controls.Remove(_browser); _browser.Dispose(); } _browser = new ChromiumWebBrowser(CefInit.ResourceRootUrl + "index.html"); _dataExchange.RegisterService(new CefDevService(_browser), true); _browser.RegisterJsObject(nameof(Cbdx), _dataExchange.Dispatcher, new BindingOptions { CamelCaseJavascriptNames = false }); _browser.Dock = DockStyle.Fill; MainPanel.Controls.Add(_browser); _browser.BringToFront(); } private void F12ToolStripButton_Click(object sender, System.EventArgs e) { _browser.ShowDevTools(); } private void ReloadToolStripButton_Click(object sender, System.EventArgs e) { CreateOrReloadCefBrowserControl(); } } }