12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- 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<IWindowControlService>(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<ICefDevService>(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();
- }
- }
- }
|