Skip to content

Instantly share code, notes, and snippets.

@tocalai
Created May 16, 2019 00:52
Show Gist options
  • Save tocalai/01fe6f58eb11dca6833d439291f32127 to your computer and use it in GitHub Desktop.
Save tocalai/01fe6f58eb11dca6833d439291f32127 to your computer and use it in GitHub Desktop.
Demo form that use cefsharp
public partial class DemoForm : Form
{
public ChromiumWebBrowser ChromeBrowser;
// the target resource uri for browser rendering
private readonly string _address;
public DemoForm(string address)
{
_address = address;
StartPosition = FormStartPosition.CenterScreen;
InitializeComponent();
// start the browser componet
InitializeChromium();
}
public void InitializeChromium()
{
// enable high dpi support
Cef.EnableHighDPISupport();
CefSettings settings = new CefSettings();
// initialize cef with the provided settings
Cef.Initialize(settings);
// create a browser component
ChromeBrowser = new ChromiumWebBrowser(_address);
// add it to the form and fill it to the form window.
this.Controls.Add(ChromeBrowser);
ChromeBrowser.Dock = DockStyle.Fill;
}
// close the browser component
private void DemoForm_FormClosing(object sender, FormClosingEventArgs e)
{
Cef.Shutdown();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment