| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- using Microsoft.Web.WebView2.Core;
- using Microsoft.Web.WebView2.WinForms;
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Configuration;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Timers;
- using System.Windows.Forms;
- namespace PrintHtmlFrom
- {
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- InitBrowser();
- }
- private void InitBrowser()
- {
- AwaitCoreWebView2Async(webView21); //设置浏览器参数
- webView21.CoreWebView2.Settings.AreDefaultScriptDialogsEnabled = true;
- webView21.CoreWebView2.NavigateToString(@"D:\index.html");
- }
- private async void AwaitCoreWebView2Async(WebView2 WebView21)
- {
- string userDataFolder = null; //"你的缓存文件夹路径";
- CoreWebView2EnvironmentOptions options = new CoreWebView2EnvironmentOptions($"--lang=zh-CN");
- var environment = await CoreWebView2Environment.CreateAsync(null, userDataFolder, options);
- // Create a WebView with the specified environment.
- await WebView21.EnsureCoreWebView2Async(environment);
- }
- private void WebView2_NavigationCompleted(object sender, CoreWebView2NavigationCompletedEventArgs e)
- {
- }
- private void WebView2_ContentLoading(object sender, CoreWebView2ContentLoadingEventArgs e)
- {
- }
- private void WebView2InitializationCompleted(object sender, CoreWebView2InitializationCompletedEventArgs e)
- {
- }
- private void WebView2_NavigationStarting(object sender, CoreWebView2NavigationStartingEventArgs e)
- {
- }
- private void Form1_Load(object sender, EventArgs e)
- {
- }
- }
- }
|