Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CefSharp WinForms Web Browser Won't Display

I have a dead simple example trying to get the CEF Browser to append on a Winforms Form. For some reason it won't display.

public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();

        CefSharp.WinForms.ChromiumWebBrowser test = new CefSharp.WinForms.ChromiumWebBrowser("http://google.com");
        this.Controls.Add(test);
    }
}

Below is the VS Solution I am using. I added the package via Nuget

like image 365
aherrick Avatar asked Dec 05 '25 13:12

aherrick


1 Answers

Your code above is a bit too dead simple :)

It's missing a call to Cef.Initialize()

See the Main() method of the CefSharp.MinimalExample.WinForms example for a working example and further details on how to use CefSharp.

You also need to give the control a DockStyle.Fill, like:

public Form1()
{
    InitializeComponent();
    var test = new CefSharp.WinForms.ChromiumWebBrowser("http://google.com")
    {
        Dock = DockStyle.Fill,
    };
    this.Controls.Add(test);
}
like image 124
jornh Avatar answered Dec 07 '25 11:12

jornh



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!