cefsharp学习笔记
Posted 我的E家园
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了cefsharp学习笔记相关的知识,希望对你有一定的参考价值。
环境: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; } } }
以上是关于cefsharp学习笔记的主要内容,如果未能解决你的问题,请参考以下文章
[原创]java WEB学习笔记61:Struts2学习之路--通用标签 property,uri,param,set,push,if-else,itertor,sort,date,a标签等(代码片段