简体   繁体   中英

Adding a Usercontrol with CefSharp to a WinForms app

I'm trying to create a user control with a CefSharp to be able to have a web browser with custom properties. The control works fine except when I try to add the control to a WebForms app with the Graphic Designer, every time I try to add the control graphically I get the same error:

Failed to create the component '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.

I have the CefSharp.Core added as a reference on both the Usercontrol and the WebFormsApp.

(Note that the control works if it is added programmatically.)

Anyone know what I'm missing?

Edit 1:

Here is the code of the user control that I have created:

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

Finally, thanks to amaitland, I figured out how to make it work. I only needed to avoid creating the component on design time, so I checked if I am on disign time:

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

This way the component is only created when in runtime.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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