什么是WebView2?

  1. Win10上对标Edge浏览器
  2. Chromium内核
  3. 简单的可视为WebBrowser组件的升级版

如何使用WebView2?

  1. 官网下载 WebView2 RunTime
  2. VS2019 NuGet搜索 WebView2,安装最新版即可

WebView2 具体使用技巧

  1. 引入 using Microsoft.Web.WebView2.WinForms;
  2. 声明 WebView2,如 var edge=new WebView2();
  3. 将窗体 Load 事件声明为 async,如 private async void ViewForm_Load(object sender, EventArgs e)
  4. edge添加到Controls中,如Controls.Add(edge);edge.Dock = DockStyle.Fill;
  5. 在窗体 Load 事件中 增加 await edge.EnsureCoreWebView2Async();//这步是必须的
  6. 设置网址,edge.Source = new Uri("https://www.cnblogs.com");

我想怎么玩?

  1. WebView2 提供 UI TidyView
  2. TidyScriptCore 提供 C# 脚本运行

TidyView

  1. 把 WebView2 封装成 TidyWebView
public class TidyWebView:WebView2
{
public TidyWebView();
public List<Typing.FuncSender> Main;
public Runner ViewRunner;
private void CoreWebView2_DOMContentLoaded(object sender, Microsoft.Web.WebView2.Core.CoreWebView2DOMContentLoadedEventArgs e);
private void TidyWebView_CoreWebView2InitializationCompleted(object sender, Microsoft.Web.WebView2.Core.CoreWebView2InitializationCompletedEventArgs e);
public string Url{get;set;}
public void Navigate(string Url)
public delegate void CallNone();
public void EvalJS(string Script);
public void EvalTidy(string Script);
private EventCollection EventList;
public int AddFunc(Typing.FuncSender func);
public int AddFunc(string Name,Typing.FuncSender func);
public void CallIndex(int Index,params object[] args);
public void Call(string Name, params object[] args);
}
  1. 将 TidyWebView 放到窗体
using System;
using System.Windows.Forms;
using System.IO;
using TidyScriptCore; namespace TidyView
{
public partial class ViewForm : Form
{
public ViewForm()
{
InitializeComponent();
edge.NavigationCompleted += Edge_NavigationCompleted;
Inner.console.host = edge;
} private void Edge_NavigationCompleted(object sender, Microsoft.Web.WebView2.Core.CoreWebView2NavigationCompletedEventArgs e)
{
Text = edge.CoreWebView2.DocumentTitle;
} TidyWebView edge = new TidyWebView(); public string CodePath = string.Empty; private async void ViewForm_Load(object sender, EventArgs e)
{
Tidy.Using(typeof(Inner));
p_web.Controls.Add(edge);
edge.Dock = DockStyle.Fill;
Icon = Properties.Resources.browser;
await edge.EnsureCoreWebView2Async();
edge.ViewRunner.Space.Create("MainForm",this);
if (File.Exists(CodePath))
{
Log.Path = TidyScriptCore.API.GetDir(CodePath) + "\\Logs.txt";
edge.ViewRunner.Environment["ScriptPath"] = CodePath;
edge.ViewRunner.Environment["ScriptDir"] = TidyScriptCore.API.GetDir(CodePath);
Tidy.EvalFile(CodePath,edge.ViewRunner);
}
}
}
}
  1. TidyScript 脚本 个人门户(密码:Tidy),基本和C#代码风格保持一致
using "Baidu.csc";
using "News.csc";
using "Weather.csc";
edge.AddFunc("search",(kw,filter_str,limit_str,page_str)=>
{
var filter=json.obj(filter_str);
var limit=json.obj(limit_str);
var page=json.obj(page_str);
var filter_lamda;
var bd=new Baidu();
//...
int index=page.start_index;
bd.search(kw,(info)=>
{
//...
if(filter.on){/*...*/}
else
{
edge.EvalJS($"_add({index++},{info});");
}
return true;
},()=>{/*...*/},page.first,page.last);
edge.EvalJS("_show_sufooter()");
});
//...
//...
edge.Main.Add(()=>
{
if(file.exists(locate("filter_code.txt")))
{
var default_code=transfer(file.read(locate("filter_code.txt")));
edge.EvalJS($"document.getElementById('filter_code').value='{default_code}'");
}
});
edge.Url="file:///"+locate("page.html");
  1. 右键你写的脚本,用TidyView.exe打开,点击BiliBili

  2. 开源项目 TidyView

  3. 打包好的示例(TidyView+示例脚本)

下一个玩具 FFMPEG Visual ,我打算这么做

  1. 将功能封装在FfmpegEx.dll中
  2. TidyView 用来 UI
  3. 写C#脚本,来桥接 FfmpegEx.dll 和 JS

C# WebView2 在你的应用中使用Chromium内核的更多相关文章

  1. centos中安装chromium和flash

    安装环境:centos 6.5 64位 在centos中安装chromium 安装Google源 cd /etc/yum.repos.d/ sudo wget http://people.CentOS ...

  2. u-boot中分区和内核MTD分区关系

    一.u-boot中环境变量与uImage中MTD的分区关系 分区只是内核的概念,就是说A-B地址放内核,C-D地址放文件系统,(也就是规定哪个地址区间放内核或者文件系统)等等. 一般我们只需要分3-4 ...

  3. linux中清理旧内核

    执行update的时候会自动升级内核,开机启动的时候会好多内核选项.所以我们要清理不需要内核. 查看当前系统使用的内核版本 uname -a Linux localhost.localdomain 3 ...

  4. .NET混合开发解决方案11 WebView2加载的网页中JS调用C#方法

    系列目录     [已更新最新开发文章,点击查看详细] WebView2控件应用详解系列博客 .NET桌面程序集成Web网页开发的十种解决方案 .NET混合开发解决方案1 WebView2简介 .NE ...

  5. Delphi中Chrome Chromium、Cef3学习笔记(四)

    原文   http://blog.csdn.net/xtfnpgy/article/details/48155323   一.遍历网页元素并点击JS: 下面代码为找到淘宝宝贝页面,成交记录元素的代码: ...

  6. Delphi中Chrome Chromium、Cef3学习笔记(三)

    原文   http://blog.csdn.net/xtfnpgy/article/details/46635871   Delphi与JS的交互问题: 一.执行简单的JS 上一篇已经讲过: chrm ...

  7. Delphi中Chrome Chromium、Cef3学习笔记(二)

    原文   http://blog.csdn.net/xtfnpgy/article/details/46635739   用Tchromium替换webbrowser 用惯了EmbeddedWB,不想 ...

  8. Delphi中Chrome Chromium、Cef3学习笔记(一)

    原文   http://blog.csdn.net/xtfnpgy/article/details/46635225   官方下载地址:https://cefbuilds.com/ CEF简介: 嵌入 ...

  9. Linux2.6.32内核笔记(5)在应用程序中移植使用内核链表【转】

    转自:http://blog.csdn.net/Deep_l_zh/article/details/48392935 版权声明:本文为博主原创文章,未经博主允许不得转载. 摘要:将内核链表移植到应用程 ...

随机推荐

  1. ts 函数重载

    class User { constructor(public readonly name: string, public readonly value: Function) {} } class D ...

  2. lua windows上使用vs编译Lua

    video 下载lua源文件 还有种方法: 创建空项目,取名lua,导入lua源文件 将luac.c移除,然后编译lua.exe 将lua.c移除,添加luac.c然后编译lua.exe后重命名位lu ...

  3. c++ 动态解析PE导出表

    测试环境是x86 main #include <iostream> #include <Windows.h> #include <TlHelp32.h> #incl ...

  4. Flutter 使用Tabbar不要Title

    原文 Demo 1 import 'package:flutter/material.dart'; void main() => runApp(MyApp()); class MyApp ext ...

  5. NGK全球启动大会圆满落幕

    加州时间2020年11月25日,NGK全球启动大会在美国硅谷圆满落幕.本次NGK全球启动大会为NGK正式在全球上线拉开了序幕. 百余位受邀嘉宾出席了本次NGK全球启动大会,其中包括NGK创始人.星盟投 ...

  6. 【PY从0到1】 一文掌握Pandas量化基础

    # 2[PY从0到1] 一文掌握Pandas量化基础 # Numpy和pandas是什么关系呢? # 在我看来,np偏向于数据细节处理,pd更偏向于表格整体的处理. # 要记住的pd内部的数据结构采用 ...

  7. spring框架aop用注解形式注入Aspect切面无效的问题解决

    由于到最后我的项目还是有个邪门的错没解决,所以先把文章大概内容告知: 1.spring框架aop注解扫描默认是关闭的,得手动开启. 2.关于Con't call commit when autocom ...

  8. Spring学习过程中遇到的No bean named 'beanId' is defined报错

    ApplicationContext applicationContext= new ClassPathXmlApplicationContext("bean.xml");Obje ...

  9. 2021-02:Teams开发平台更新概述

    作为2021年工作计划的一部分,我会在每月的第三个星期五发布Teams开发平台的更新报告,给大家整理和讲解最新的平台功能,以及特色场景.这是第一篇文章,我会挑选截至到2月份一些重要的更新,以后每月的更 ...

  10. CSS绘制三角形和箭头

    <html> <head> <meta charset="utf-8"> <title>CSS绘制三角形和箭头</title& ...