标签:ext threading main 学习 class ted features ack user
环境:VS2015+cefsharp 57.0
全部代码如下:
using System; using CefSharp; 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 mycef { public partial class Form1 : Form { public ChromiumWebBrowser webBrower; public Form1() { InitializeComponent(); Load += Form1_Load; } private void Form1_Load(object sender, EventArgs e) { string path = "www.029gc.cn"; webBrower = new ChromiumWebBrowser(path); webBrower.LifeSpanHandler = new OpenPageSelf(); //限制网页内部打开 webBrower.Dock = DockStyle.Fill;//填充方式 this.Controls.Add(webBrower); } private void button3_Click(object sender, EventArgs e) { // webBrower.GetBrowser().Reload(true); string url = webBrower.GetMainFrame().Url.ToString(); //获取网址 MessageBox.Show(url); } private void button1_Click(object sender, EventArgs e) { webBrower.GetBrowser().GoBack(); } private void button2_Click(object sender, EventArgs e) { webBrower.GetBrowser().GoForward(); } } internal class OpenPageSelf : ILifeSpanHandler { public bool DoClose(IWebBrowser browserControl, IBrowser browser) { return false; } public void OnAfterCreated(IWebBrowser browserControl, IBrowser browser) { } public void OnBeforeClose(IWebBrowser browserControl, IBrowser browser) { } public bool OnBeforePopup(IWebBrowser browserControl, IBrowser browser, IFrame frame, string targetUrl, string targetFrameName, WindowOpenDisposition targetDisposition, bool userGesture, IPopupFeatures popupFeatures, IWindowInfo windowInfo, IBrowserSettings browserSettings, ref bool noJavascriptAccess, out IWebBrowser newBrowser) { newBrowser = null; var chromiumWebBrowser = (ChromiumWebBrowser)browserControl; chromiumWebBrowser.Load(targetUrl); return true; } } }
标签:ext threading main 学习 class ted features ack user
原文地址:http://www.cnblogs.com/jeib/p/7993137.html