C# CEF 封装UserControl
2021-02-16 08:22
标签:ali zh-cn windows .com lin sign hand rom col C# CEF 封装UserControl 标签:ali zh-cn windows .com lin sign hand rom col 原文地址:https://www.cnblogs.com/zhaogaojian/p/8411181.htmlusing 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 UCBase()
{
InitializeComponent();
if (!DesignMode)
{
Init();
}
}
public ChromiumWebBrowser browser = null;//这句话不能放构造函数之前,不知道为什么否则会报错。
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;
browser.MouseClick += new MouseEventHandler(BrowserMouse_Click);
}
public void LoadHtml(String html)
{
browser.LoadHtml(html.ToString(), "http://customrendering/");
//browser.Refresh();
}
public void LoadUrl(String url)
{
browser.Load(url);
}
public void BrowserMouse_Click(object sender,MouseEventArgs e)
{
if(e.Button==MouseButtons.Right)//禁止鼠标右键
{
return;
}
return;
}
}
}
文章标题:C# CEF 封装UserControl
文章链接:http://soscw.com/index.php/essay/56019.html