簡體   English   中英

如何從c#wpf中的webbrowser控件中動態創建的網頁引用css樣式表?

[英]How to reference a css style sheet from a dynamically created webpage in a webbrowser control in c# wpf?

我動態創建一個網頁,並使用Webbrowser控件的NavigateToString方法顯示它。 我想引用這樣的樣式表:

<link rel=stylesheet type="text/css" href="style.css">

我將style.css放在應用程序workdir中。 但它不起作用。 當我將創建的網站保存到html文件時,將style.css放在它旁邊並在瀏覽器中打開它,它會正確顯示。

我該如何引用這樣的靜態文件?

你可以這樣做:

導航到html字符串之前更改它的Css地址

string html = System.IO.File.ReadAllText(@"Your html file").Replace("BaseAdress", @"location of css file");

例:

Html文件:

<html>
<head>
<link rel=stylesheet type="text/css" href="BaseAdress\style.css">
</head>
<body>
<p>hi</p>
</body>
</html>

CS代碼:

string html = System.IO.File.ReadAllText(@"E:\1.html").Replace("BaseAdress",@"E:\");
webBrowser1.NavigateToSting(html);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM