Visual Studio不允许我通过设计器将CefSharpBrowserControl添加到窗体 [英] Visual Studio is not letting me add CefSharpBrowserControl to a form via the designer

查看:237
本文介绍了Visual Studio不允许我通过设计器将CefSharpBrowserControl添加到窗体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我决定尝试CefSharp扩展程序,我遇到的第一件事是什么?

So I decided to try out the CefSharp extension, and what's the first thing I encounter? An error that doesn't let me use the add-on.

这太令人沮丧了,因为我已经做了所有事情,甚至管理员或创建者都说过要做在我去过的任何论坛上。我试图只在CEFSharp的GitHub上编译源代码,但这没有用。

This is ridiculously frustrating because I've done every single thing even the administrator or creator has said to do on any forum I've been on. I tried to just compile the source code on the CEFSharp's GitHub, but that didn't work.

如果我很残酷,我认为他们应该提供一个预编译的.dll文件或一组.dll文件,您可以将它们添加到引用中,而不仅仅是期望您自己做。

If I'm brutally honest, I think that they should just provide a pre-compiled .dll file or group of .dll files that you can just add to the references, instead of just expecting you to do it yourself. It's just a pain, CEFSharp.

我尝试过将配置设置为x64和任何CPU。我尝试引用与CEFSharp相关的几个不同的dll。我曾尝试以编程方式添加浏览器元素,并且可以,但是我无法执行任何操作(例如,网页加载完成后执行代码)。到目前为止,所有这些解决方案都不起作用。

I've tried putting the Configuration to x64 AND Any CPU. I've tried making references to several different dlls associated to CEFSharp. I've tried to add the browser element programmatically, and that's worked, but I can't do anything with it (such as execute code when the webpage is done loading). So far none of these solutions have worked at all.

Imports CefSharp
Imports CefSharp.WinForms
Public Class Browser
       Dim browser As New _ 
       CefSharp.WinForms.ChromiumWebBrowser("https://google.com/")
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles _ 
    MyBase.Load
       Me.Controls.Add(browser)
       browser.Parent = Panel1
       browser.Dock = DockStyle.Fill
    End Sub
End Class

每当我想通过设计器工具箱将浏览器控件添加到表单中时,它都不会不要让我。它一直显示此错误框,显示无法加载CefSharpBrowser,无法从工具箱中删除。或类似的规定。

Any time I want to add the browser control to my form via the designer toolbox, it won't let me. It keeps showing this error box that says "Failed to load CefSharpBrowser, deleting from the toolbox." Or something along those lines. It's supposed to just be able to drop into the designer, but it's obviously not.

推荐答案

关于CefSharp的google组的讨论也与此类似。 :将CefSharp控件添加到工具箱名称空间中的名称 WebView不存在

There are similar discussions on CefSharp's google group: Adding CefSharp control to the toolbox and The name "WebView" does not exist in the namespace.

他们说Visual Studio在使用混合模式(C ++ / CLR)程序集时有一些限制。 CefSharp中没有开箱即用的Visual Studio设计器支持。关于如何操作,有一些技巧,但我没有认为花时间在上面值得。大多数人只是接受事实并继续前进。

They say that Visual Studio has some limitations when using a mixed mode (C++/CLR) assembly. There is no Visual Studio designer support out of the box in CefSharp. There is some hack about how to do it, but I do not think it worth it to even spend time on it. Most people just accept the fact and move on.

我们成功地将CefSharp用于我们的一个项目,并以编程方式将ChromiumWebBrowser控件添加到窗体中,与您的操作非常相似

We successfully use CefSharp for one of our projects and we add ChromiumWebBrowser control to a form programmatically, very similar to how you did it in your sample.


我尝试以编程方式添加浏览器元素,但是
可以,但是我可以t做任何事(例如在
网页加载完成时执行代码)。到目前为止,所有这些解决方案都根本无法使用

I've tried to add the browser element programmatically, and that's worked, but I can't do anything with it (such as execute code when the webpage is done loading). So far none of these solutions have worked at all.

有一个LoadingStateChanged事件,您可以使用它来监视Web浏览器控件的状态。我们用它来显示进度指示,直到我们的网页完全加载为止。我们的操作方法如下:

There is a LoadingStateChanged event which you can use to monitor the status of a web browser control. We use it to show progress indication until our web page is fully loaded. Here is how we do it:

private System.Windows.Forms.PictureBox picProgress; 
bool loaded = false;   
ChromiumWebBrowser browse;      

public Main()
{
   var uiUrl = "some url or local html file";
   browse = new ChromiumWebBrowser(uiUrl);
   browse.Dock = DockStyle.Fill;
   Controls.Add(browse);
   browse.LoadingStateChanged += Browse_LoadingStateChanged;
}

private void Browse_LoadingStateChanged(object sender, LoadingStateChangedEventArgs e)
{
    if (!e.IsLoading)
    {
        picProgress.BeginInvoke((Action)(() => {
            loaded = true;
            picProgress.Visible = false;
            browse.Visible = true;
        }));
    }
    else
    {
        browse.BeginInvoke((Action)(() => {
            loaded = false;
            browse.Visible = false;
        }));
    }
}

对不起,它在C#中,但是我想你可以轻松地使其适应VB.net。

Sorry, it is in C#, but I think you can easily adapt it for VB.net.

这篇关于Visual Studio不允许我通过设计器将CefSharpBrowserControl添加到窗体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆