C# CEF 封装UserControl

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

namespace BaseUserControl
{
    public partial class UCBase : UserControl
    {
     public ChromiumWebBrowser browser = null;
     public UCBase() { InitializeComponent(); if (!IsDesignMode()) { Init(); } }

      public bool IsDesignMode()
      {
        bool returnFlag = false;

        //#if DEBUG
        if (LicenseManager.UsageMode == LicenseUsageMode.Designtime)
        {
          returnFlag = true;
        }
        if (Process.GetCurrentProcess().ProcessName == "devenv")
        {
          returnFlag = true;
        }
        //#endif


        return returnFlag;
      }

    public void Init()
        {
            var Settings = new CefSettings
            {
                Locale = "zh-CN"

            };
            Cef.Initialize(Settings);
            browser = new ChromiumWebBrowser("http://customrendering/");
            browser.BackColor = Color.LightGray;
            panelExIE.Controls.Add(browser);
            browser.Dock = DockStyle.Fill;
        }
        public void LoadHtml(String html)
        {
            browser.LoadHtml(html.ToString(), "http://customrendering/");
            //browser.Refresh();
            
        }
        public void LoadUrl(String url)
        {
            browser.Load(url);
        }
    }
}

 

posted @ 2018-02-03 23:13  zhaogaojian  阅读(500)  评论(0编辑  收藏  举报