C# NET如何在WebBrowser控件上显示图像?
如何在C#/.NET中的webbrowser控件上显示图像?我在做类似的事情C# NET如何在WebBrowser控件上显示图像?,c#,.net,webbrowser-control,C#,.net,Webbrowser Control,如何在C#/.NET中的webbrowser控件上显示图像?我在做类似的事情 webBrowser1.DocumentText = "<html><head></head><body><img src=imagelocationURL.png/></body></html>" webBrowser1.DocumentText=“” 但是图像没有出现。我做错了什么?我猜有两件事:或者,正如codeka指出的,您
webBrowser1.DocumentText = "<html><head></head><body><img src=imagelocationURL.png/></body></html>"
webBrowser1.DocumentText=“”
但是图像没有出现。我做错了什么?我猜有两件事:或者,正如codeka指出的,您缺少imagelocationURL.png周围的引号(单引号或双引号),并且标记没有呈现;否则,您需要检查.png文件的位置。当然,请添加引号:
webBrowser1.DocumentText = "<html><head></head><body><img src='imagelocationURL.png'/></body></html>"
webBrowser1.DocumentText=“”
然后,尝试对.png文件的路径进行硬编码,看看是否有效:
webBrowser1.DocumentText = "<html><head></head><body><img src='C:/Temp/imagelocationURL.png'/></body></html>"
webBrowser1.DocumentText=“”
如果硬编码路径起作用,那么您只需要使用代码来提取与硬编码路径等效的路径。如果您可以接受文件中的内容而不是传递整个html内容,则可以通过以下操作轻松实现:
if (File.Exists(filetoopen))
this.webBrowser1.Url = new Uri(String.Format(filetoopen));
什么是“imagelocationURL.html”?此外,您应该在HTML中的属性值周围加引号…可能是我需要显示某个位置的png图像。对不起,在示例中,我指的是.png。编辑