39 lines
1.1 KiB
C#
39 lines
1.1 KiB
C#
using Microsoft.Web.WebView2.Core;
|
|
using Microsoft.Web.WebView2.WinForms;
|
|
using System;
|
|
using System.Linq;
|
|
|
|
namespace AIProofread.core
|
|
{
|
|
public class WebView2EventHandler
|
|
{
|
|
public static void WebView2NavigationCompleted(object sender, CoreWebView2NavigationCompletedEventArgs e)
|
|
{
|
|
if (e.IsSuccess)
|
|
{
|
|
return;
|
|
}
|
|
string errorPageHtml = @"
|
|
<html>
|
|
<head>
|
|
<title>加载失败</title>
|
|
<style>
|
|
body { font-family: sans-serif; text-align: center; padding-top: 50px; background-color: #f0f0f0; }
|
|
h1 { color: #d00; }
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<h1>页面加载失败</h1>
|
|
<p>请检查您的网络连接或稍后再试。</p>
|
|
</body>
|
|
</html>";
|
|
if (e.NavigationId == 0)
|
|
{
|
|
(sender as WebView2).CoreWebView2.NavigateToString(errorPageHtml);
|
|
}
|
|
|
|
|
|
}
|
|
}
|
|
}
|