将带有 CefSharp 的用户控件添加到 WinForms 应用程序

Adding a Usercontrol with CefSharp to a WinForms app

我正在尝试使用 CefSharp 创建一个用户控件,以便能够拥有具有自定义属性的 Web 浏览器。该控件工作正常,除非我尝试使用图形设计器将控件添加到 WebForms 应用程序,每次我尝试以图形方式添加控件时,我都会遇到相同的错误:

创建组件失败'MyComponent'

System.IO.FilenotFoundException: Could not load file or assembly 'CefSharp.Core, Version=65.0.0.0, Culture=neutral, PublicKeyToken=xxxxxxxxxxxx' or one of its dependencies. the system cannot find the file specified.

我在 Usercontrol 和 WebFormsApp 上添加了 CefSharp.Core 作为参考。

(请注意,如果以编程方式添加该控件,该控件将起作用。)

有人知道我错过了什么吗?

编辑 1:

这是我创建的用户控件的代码:

using System;
using System.Windows.Forms;
using CefSharp.WinForms;
using CefSharp;

namespace ControlTest
{
    public partial class UserControl1: UserControl
    {
        public ChromiumWebBrowser browser;
        public UserControl1()
        {
            InitializeComponent();
        }

        private void UserControl1_Load(object sender, EventArgs e)
        {
            CefSettings settings = new CefSettings();
            Cef.Initialize();
            browser = new ChromiumWebBrowser("www.google.com");
            this.panel1.Controls.Add(browser);
        }
    }
}

最后,感谢 amaitland,我想出了如何让它发挥作用。我只需要避免在设计时创建组件,所以我检查了我是否在设计时:

if (LicenseManager.UsageMode != LicenseUsageMode.Designtime)
    InitializeComponent();

这样组件只在运行时创建。