Load external files such as css into webbrowser control

我们两清 提交于 2019-12-25 02:24:45

问题


I'm embedding a web page in my program using this method:

WebBrowser1.DocumentText = "<b>hello</b> world <img src=""/images/amiga.png"" />"

so the html is in the program, but I would like to load the css and images from an outside place (such as ./themes/default/style.css).

So where do I put the files during development, and what do I makes the paths?

I want the html to be static but allow users to change the css.

edit: actually, since it's in the code, if there's something in vb that puts in the program location, that could work, like %programlocation% + "/themes/default/style.css"

and I'm also looking into using gecko instead of the ie rendering engine, so if anyone knows a good way to do it let me know


回答1:


So you're trying to do this purely from the filesystem, and with no web server? I'm not completely sure if this would work, but you could try doing:

WebBrowser1.DocumentText = "<head><link rel=""StyleSheet"" HREF=""file:///" & Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location).Replace("\\", "/") & "/themes/default/style.css"" TYPE=""text/css"" /></head><body><b>hello</b> world <img src=""/images/amiga.png"" /></body></html>"


来源:https://stackoverflow.com/questions/12657875/load-external-files-such-as-css-into-webbrowser-control

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!