• 保存到桌面加入收藏设为首页
技术

C# 调用CefSharp.WinForms实现支持H5的浏览器

作者:CrazyEditor   来源:CrazyEditor.cn  
1.使用nuget下载安装CefSharp.WinForms。
2.组装代码:

  public ChromiumWebBrowser chromeBrowser;
  
  private void button_OK_Click(object sender, EventArgs e)
   {
     InitializeChromium();
   }

  //初始化浏览器并启动
  public void InitializeChromium()
   {
    CefSettings settings = new CefSettings();
    // Initialize cef with the provided settings
    Cef.Initialize(settings);
    // Create a browser component
   ChromiumWebBrowser chromeBrowser = new     ChromiumWebBrowser(System.IO.Directory.GetCurrentDirectory()+"\\"+"newpage.html");
    // Add it to the form and fill it to the form window.
    this.Controls.Add(chromeBrowser);
    chromeBrowser.Dock = DockStyle.Fill;
    }

    //窗体关闭时,记得停止浏览器
    private void Form1_FormClosing(object sender, FormClosingEventArgs e)
    {
      Cef.Shutdown();
    }        


本栏最新更新
本栏推荐
阅读排行

(C) 2018-2019 疯狂小编