简体   繁体   English

CefSharp WinForms Web浏览器无法显示

[英]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. 我有一个简单的例子试图让CEF浏览器附加到Winforms表单上。 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. 以下是我正在使用的VS解决方案。 I added the package via Nuget 我通过Nuget添加了包

Your code above is a bit too dead simple :) 你上面的代码有点死了简单:)

It's missing a call to Cef.Initialize() 它缺少对Cef.Initialize()的调用

See the Main() method of the CefSharp.MinimalExample.WinForms example for a working example and further details on how to use CefSharp. 有关工作示例,请参阅CefSharp.MinimalExample.WinForms 示例Main()方法,以及有关如何使用CefSharp的更多详细信息。

You also need to give the control a DockStyle.Fill , like: 您还需要为控件提供DockStyle.Fill ,如:

public Form1()
{
    InitializeComponent();
    var test = new CefSharp.WinForms.ChromiumWebBrowser("http://google.com")
    {
        Dock = DockStyle.Fill,
    };
    this.Controls.Add(test);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM