CefSharp WinForms Web Browser Won't Display

允我心安 提交于 2019-11-30 19:16:22

问题


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


回答1:


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);
}


来源:https://stackoverflow.com/questions/26307444/cefsharp-winforms-web-browser-wont-display

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!