mirror of
https://gitlab.com/walljm/dynamicbible.git
synced 2025-07-27 09:29:59 -04:00
61 lines
2.0 KiB
C#
61 lines
2.0 KiB
C#
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"));
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// Initializes the browser control and adds it to the form.
|
|
/// </summary>
|
|
/// <returns>The newly created browser</returns>
|
|
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();
|
|
}
|
|
|
|
}
|
|
} |