Skip to content

Instantly share code, notes, and snippets.

@privatedev11
Created December 12, 2020 19:02
Show Gist options
  • Save privatedev11/457c7cf69ccaec85e8f64d5dab871153 to your computer and use it in GitHub Desktop.
Save privatedev11/457c7cf69ccaec85e8f64d5dab871153 to your computer and use it in GitHub Desktop.
Add a web browser in C# using CefSharp

CEFSharp

CEFSharp is a great nuget package for putting Chromium in your C# program. I will be using WinForms.

1. Get the package

Get the package here: https://www.nuget.org/packages/CefSharp.WinForms/

2. Add the imports

Add the following to the imports section: ''' using CefSharp; using CefSharp.WinForms; '''

3. Add the code!

Paste this code in: ''' public ChromiumWebBrowser browser;

public void InitBrowser() { Cef.Initialize(new CefSettings()); browser = new ChromiumWebBrowser("www.google.com"); this.Controls.Add(browser); browser.Dock = DockStyle.Fill; } ''' Change google to the site you want to view

3. Call InitBrowser()

Call InitBrowser at InitializeConponent ''' InitBrowser(); '''

4. Run it!

When running, you should see the site!!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment