【问题标题】:Adding a Usercontrol with CefSharp to a WinForms app将带有 CefSharp 的用户控件添加到 WinForms 应用程序
【发布时间】:2018-08-22 19:32:42
【问题描述】:

我正在尝试使用 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 我已经看到了这个问题,现在我可以通过从构造函数中删除 InitializeComponent() 来加载控件,但是随后控件没有加载并且我无法使用它,所以它对我不起作用:(
  • 没有看到你的代码,我只是在猜测。如果你还没有,你需要阅读stackoverflow.com/help/mcve
  • @amaitland 感谢您的建议,我在这里很新手...现在我要更新问题。
  • 只在非设计模式下创建和添加浏览器,见stackoverflow.com/a/4346899/4583726

标签: c# user-controls chromium-embedded cefsharp


【解决方案1】:

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

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-11
    • 1970-01-01
    • 2016-08-02
    • 1970-01-01
    • 2011-03-09
    相关资源
    最近更新 更多