• cefsharp学习笔记


    环境:VS2015+cefsharp 57.0

    全部代码如下:

    1、要初始化,否则不能刷新

      

    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();
    SetInit();
    
    }
    
    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);
    
    }
    
    public static void SetInit()
    {
    CefSettings setting = new CefSettings();
    Cef.Initialize(setting);
    }
    
    private void button3_Click(object sender, EventArgs e)
    {
    
    
    webBrower.Reload(true);
    }
    
    private void button1_Click(object sender, EventArgs e)
    {
    webBrower.GetMainFrame().Browser.GoBack();
    }
    
    private void button2_Click(object sender, EventArgs e)
    {
    webBrower.GetMainFrame().Browser.GoForward();
    }
    
    private void Form1_FormClosing(object sender, FormClosingEventArgs e)
    {
    
    
    }
    }
    
    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; 
    }
    }
    
     
    
    }
    

      

  • 相关阅读:
    [整理]正睿 CSP 七连测划水
    关于我想了好久才想出这题咋做这档事
    关于我想了好久才想出这题咋做这档事
    关于我想了好久才想出这题咋做这档事
    [考试总结]ZROI-21-NOIP冲刺-TEST11 总结
    关于我想了很久才想出这题咋做这档事
    [题解]POJ3415 Common Substrings
    [题解]CF1073G Yet Another LCP Problem
    [题解]Codeforces Round #751 (Div. 2) 题解
    [考试总结]ZROI-21-NOIP冲刺-TEST10 总结
  • 原文地址:https://www.cnblogs.com/jeib/p/7993137.html
Copyright © 2020-2023  润新知