Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
223 views
in Technique[技术] by (71.8m points)

vb.net - Visual Studio is not letting me add CefSharpBrowserControl to a form via the designer

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.

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.

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.

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

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.

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.

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.

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.

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

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...