using System.IO; using System.Windows.Forms; using CefSharp; using CefSharp.WinForms; namespace DynamicBible { public partial class frmMain : Form { private readonly IWinFormsWebBrowser _browser; public frmMain() { InitializeComponent(); _browser = initializeBrowserControl(); //// load the html into the browser //var html = System.IO.File.ReadAllText("index.html"); //_browser.LoadHtml(html, Path.Combine(Directory.GetCurrentDirectory(), "index.html")); } /// /// Initializes the browser control and adds it to the form. /// /// The newly created browser private IWinFormsWebBrowser initializeBrowserControl() { // NOTE: Cef can only be initialized once or an exception will be thrown if (!Cef.IsInitialized) { var cs = new CefSettings { BrowserSubprocessPath = Path.Combine(Directory.GetCurrentDirectory(), "lib", "CefSharp.BrowserSubprocess.exe"), LocalesDirPath = Path.Combine(Directory.GetCurrentDirectory(), "lib", "locales"), }; cs.CefCommandLineArgs.Add("allow-file-access-from-files", "allow-file-access-from-files"); Cef.Initialize(cs); } // create the browser, giving it an empty URL var browser = new ChromiumWebBrowser(Path.Combine(Directory.GetCurrentDirectory(), "index.html")) { Dock = DockStyle.Fill }; // add the browser to the form and make sure the z-order is correct this.Controls.Add(browser); browser.BringToFront(); return browser; } private void devToolsToolStripMenuItem_Click(object sender, System.EventArgs e) { _browser.ShowDevTools(); } } }