简体   繁体   中英

C# WebBrowser control not displaying custom HTML

I have a web browser control that for some reason isn't loading my HTML:

 string updatingChatHTML = ""
        + "<HTML>    "
        + "<head>"
        + "<style>"
        + "body {"
        + "  margin: 0px;"
        + "  padding: 0px;"
        + "  background: " + chatBackground + ";\n"
        + "  Font-Family: Arial;"
        + "  font-size: 11px; "
        + "  text-align: left;"
        + "}"
        + "</style>"
        + "</head>"
        + "<body>";
txtChat.DocumentText = updatingChatHTML + "</body></HTML>";

(txtChat is my WebBrowser Control).

The weird thing is, it was working before I changed something, but I can't figure out what I changed that caused it to stop working.

I have a breakpoint set to just after the last line above, and I can see that updatingChatHTML has the proper value it's meant to, but txtChat.DocumentText still has a value of <HTML></HTML>\\0 .

I thought maybe it was an initialisation thing, so I added txtChat.Navigate("about:blank"); prior to any assignment, but it still doesn't work.

This event actually gets fired quite often though, and the first time/two times, it doesn't work, but after the form is finished loading it seems to, but it's already the last thing to happen on my Form_Load.

Any suggestions?

Attempting to set the DocumentText property when

  • no document is loaded
  • or the browser control is not in a ready state (eg currently loading a document)

will cause the property assignment to fail silently.

After calling the Navigate function you should monitor the DocumentCompleted event for notification of when the navigation operation completes.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM