1

这样我尝试将 html 数据添加到 Web 浏览器控件。

private void Adddata()
{
webBrowser1.DocumentText =
"<html><body>Please enter your name:<br/>" +
"<input type='text' name='userName'/><br/>" +
"<a href='http://www.microsoft.com'>continue</a>" +
"</body></html>";
}

这可行,但是当我Adddata()重复调用例程时,只会添加第一次数据,但从下一次开始不会添加任何数据。我只想重复添加数据。有什么出路吗。

4

2 回答 2

0

改变

webBrowser1.DocumentText = //blah

webBrowser1.DocumentText += //blah

嗯,不是真的。对 html 这样做不是最好的主意。我会做的是

//in class def
bool firstTime;
//in method
bool firstTimeLcl = firstTime
firstTime = false;
if (firstTimeLcl)
{
//write header
} 
else
{
String.Replace(/*closing tags*/, "");
}
//write everything within body
//write closing tags
于 2013-02-18T13:42:09.573 回答
0

你可以使用这个:

webBrowser1.DocumentText +=

但是现在当你不能用许多 body 和 html 标签添加这段代码时。始终使用一个 html 和 body 标签构建新字符串。只需在里面附加html代码。

于 2013-02-18T13:45:12.113 回答