zoukankan      html  css  js  c++  java
  • 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; 
    }
    }
    
     
    
    }
    

      

  • 相关阅读:
    win10系统下office 2019激活
    如何根据【抖音分享链接】去掉抖音水印
    Java多线程学习之ThreadLocal源码分析
    Java多线程学习之synchronized总结
    Java多线程学习之线程的取消与中断机制
    Java多线程学习之Lock与ReentranLock详解
    Java多线程学习之线程池源码详解
    MyBatis 一、二级缓存和自定义缓存
    Spring 高级依赖注入方式
    Spring 依赖注入的方式
  • 原文地址:https://www.cnblogs.com/jeib/p/7993137.html
Copyright © 2011-2022 走看看