开发者

C# .NET How can I show an image on WebBrowser control?

How can I show an image on a webbrow开发者_JAVA技巧ser control in C#/.NET? I'm doing something like

webBrowser1.DocumentText = "<html><head></head><body><img src=imagelocationURL.png/></body></html>"

but the image doesn't appear. What am I doing wrong?


I would guess one of two things: either that, as codeka points out, you are missing the quotes (single or double) around imagelocationURL.png and the tag is not rendering; or else you need to examine the location of your .png file. For sure, add the quotes:

webBrowser1.DocumentText = "<html><head></head><body><img src='imagelocationURL.png'/></body></html>" 

Then, try hardcoding the path to your .png file and see if that works:

webBrowser1.DocumentText = "<html><head></head><body><img src='C:/Temp/imagelocationURL.png'/></body></html>"

If the hardcoded path works, then you just need to play around with your code to pull out the equivalent of the hardcoded path.


If you can live with the content being in a file instead of passing the whole html content, you can easily achieve it by doing this:

if (File.Exists(filetoopen))
                this.webBrowser1.Url = new Uri(String.Format(filetoopen));
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜