C# 通过 HtmlDocument 操作HTML节点时,会发生不停地刷新的情况,在对html文档操作后加以判断即可解决这种问题。
Public Sub setMainUlr(ByVal WebBrowser1 As WebBrowser)
Dim pElem As HtmlElement = Nothing
'即时信息页面
pElem = WebBrowser1.Document.All("myFrame")
If Not pElem Is Nothing Then
If pElem.GetAttribute("src") <> myFrameUrl Then
Dim ax As AccessXml = New AccessXml()
pElem.SetAttribute("src", myFrameUrl)
End If
End If
'展示图片页面
pElem = WebBrowser1.Document.All("slice")
If Not pElem Is Nothing Then
If pElem.GetAttribute("src") <> pictureUrl Then
Dim ax As AccessXml = New AccessXml()
pElem.SetAttribute("src", pictureUrl)
End If
End If
End Sub
通用方法:
private void DisplayCustomersTable()
{
DataSet customersSet = new DataSet();
DataTable customersTable = null;
SqlDataAdapter sda = new SqlDataAdapter("SELECT * FROM Customers", "Data Source=localhost;Integrated Security=SSPI;Initial Catalog=Northwind;");
sda.Fill(customersTable);
customersTable = customersSet.Tables[0];
if (webBrowser1.Document != null)
{
HtmlElement tableRow = null;
HtmlElement headerElem = null;
HtmlDocument doc = webBrowser1.Document;
HtmlElement tableElem = doc.CreateElement("TABLE");
doc.Body.AppendChild(tableElem);
HtmlElement tableHeader = doc.CreateElement("THEAD");
tableElem.AppendChild(tableHeader);
tableRow