我使用的是 Microsoft Visual Studio 2005,我可以使用以下方式加载网页
string exePath = Application.ExecutablePath ;
int n = exePath.LastIndexOf("\\");
// the web page & image is in the same directory as the executable
string filename = exePath.Substring(0, n)+ "\\switchboard.htm";
webBrowser1.DocumentStream = new FileStream(filename, FileMode.Open);
网页的文本加载正常,但是这个
<img src="cardpack1.jpg" height="200" alt="card">
导致图像损坏。
图像文件与 html 文件位于同一目录中。 我什至不确定要用谷歌搜索什么。我发现的所有问题似乎都在做 更奇特的事情,比如从资源包中解析图像并尝试动态地 显示/不显示图像。
因此,我们将不胜感激任何建议(即使它只是... google for x, y, z)
最佳答案
为什么不直接使用 WebBrowser.Navigate方法代替。 URI 可以是本地文件。使用 Path 方法创建字符串也是一个好主意。
string exePath = Application.ExecutablePath;
string htmPath = Path.Combine( Path.GetDirectoryName(exePath) , "switchboard.htm");
webBrowser1.Navigate(htmPath);
关于c# - 如何解析由 WebBrowser 控件加载的 HTML 文件中的图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4866543/