我正在使用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文件位于同一目录中。
我什至不知道谷歌。我发现的所有问题似乎都在做
更奇特的事情,例如从资源束中解析图像并尝试动态地
显示/不显示图像。

因此,任何建议都将不胜感激(即使只是... x,y,z的google)

最佳答案

为什么不只是使用WebBrowser.Navigate方法呢? URI可以是本地文件。使用Path方法创建字符串也是一个好主意。

     string exePath = Application.ExecutablePath;
     string htmPath = Path.Combine( Path.GetDirectoryName(exePath) , "switchboard.htm");

     webBrowser1.Navigate(htmPath);

08-05 01:50