c# - 如何解析由 WebBrowser 控件加载的 HTML 文件中的图像

标签 c# .net winforms webbrowser-control

我使用的是 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/

相关文章:

.net - F# 库中是否有任何 "List.divideAt"HOF?

.net - .net core 2.0 中的持久身份验证 cookie

c# - 如何将锯齿状数组绑定(bind)到 DataGridView 中?

c# - 在哪里可以获取Winforms .NET的自定义控件?

c# - 如何声明通用异步任务?

c# - 如何创建 FIX partyID 组?

c# - 是否可以结合使用 ValidationRules 和 INotifyDataErrorInfo 进行 wpf 验证?

c# - MVVM - 从 View 模型关闭一个窗口

.NET Rx Koans : Why does this test case fail?

c# - 在 if 语句中比较字符串