1

I was using the .Net WebBrowser object but don't like the messy way the compatibility mode works. So I switched to CEFSharp object.

However, the object doesn't display in my form. I looked at the Example Winform project with CEFSharp but it doesn't seem to display it in a winform but runs it as a separate application which isn't want i want.

I figure I am missing some obvious method or property that must be set initially. In the code below I have what I am using for CEFSharp and you will see two lines commented out which is what I was using for .Net WebBrowser that worked.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using CefSharp.WinForms;

namespace GoogleSiren
{
public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
    }

    private void Form1_Load(object sender, EventArgs e)
    {
        ChromiumWebBrowser myBrowser = new ChromiumWebBrowser("http://wwww.cnn.com");
        //WebBrowser myBrowser = new WebBrowser();

        //myBrowser.Navigate("http://www.cnn.com");
        myBrowser.Location = new Point(200, 200);
        myBrowser.Size = new Size(500, 300);
        this.Controls.Add(myBrowser);
    }
}

}

4

2 回答 2

0

Try setting the Size and Location as part of the constructor:

ChromiumWebBrowser myBrowser = new ChromiumWebBrowser("http://wwww.cnn.com") 
{
   Location = new Point(200, 200),
   Size = new Size(500, 300)
};
this.Controls.Add(myBrowser);
于 2015-05-24T08:58:11.733 回答
0

My code was missing Cef.Initialize() call. Once I added that it worked fine.

于 2016-09-12T14:02:14.483 回答