在加载 HTML 文件时指定编码为 UTF-8可以使用 StreamReader
类的另一个重载方法,并显式指定编码类型。以下是修改后的代码示例:
string currentDirectory = Environment.CurrentDirectory;
string htmlFilePath = Path.Combine(currentDirectory, "docs", "example.html");
using (var streamReader = new StreamReader(htmlFilePath, Encoding.UTF8))
{
webBrowser.NavigateToString(streamReader.ReadToEnd());
}
使用 StreamReader
的另一个构造函数来指定编码类型为 UTF-8。然后,使用 ReadToEnd
方法读取整个文件内容,并使用 NavigateToString
方法将 HTML 内容加载到 webBrowser
控件中。
请确保将 "docs"
和 "TileSize.html"
替换为实际的文件夹和文件名。