加载外部文件,如css到webbrowser控件 [英] Load external files such as css into webbrowser control

查看:264
本文介绍了加载外部文件,如css到webbrowser控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用此方法在我的程序中嵌入网页:

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

所以html是在程序中,但我想从外部加载css和图像(例如./themes/default/style.css)。



那么我在开发过程中把文件放在哪里,我要做什么路径? p>

我希望html是静态的,但允许用户更改css。



strong>实际上,因为它在代码中,如果有一些在vb放在程序位置,这可以工作,如%programlocation%+/themes/default/style.css



解决方案

所以你试图这样做纯粹从文件系统,没有网络服务器?我不完全确定这是否会工作,但你可以尝试:

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


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

解决方案

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>"

这篇关于加载外部文件,如css到webbrowser控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆