Load in memory text into WebBrowser control

前端 未结 3 812
灰色年华
灰色年华 2021-02-15 17:52

On the .Net WebBrowser control the only way I can see to load a page to it is to set the URL property. But I would like to instead give it some HTML code that I already have in

相关标签:
3条回答
  • 2021-02-15 18:19

    Also, generally, anywhere you can use a Stream, you can use MemoryStream to wrap data you have in memory.

    0 讨论(0)
  • 2021-02-15 18:23

    You want the DocumentText Property:

    http://msdn.microsoft.com/en-us/library/system.windows.forms.webbrowser.documenttext.aspx

    ?

    from http://www.codeguru.com/forum/showpost.php?p=1691329&postcount=9 : Also you should provide a couple things:

    • Don't set DocumentText in the constructor. Use Form_Load or your own method. If you set DocumentText in the constructor, you will not be able to set it again anywhere in the application. Be sure to check that the Form Designer hasn't set it either.

    • You can only set DocumentText once per method call. This is odd and most likely a bug, but it's true. For example: setting DocumentText in a for-loop will only set properly on the first iteration of the loop. You can however, create a small method to set DocumentText to the passed in string, then call this method in a for-loop.

    0 讨论(0)
  • 2021-02-15 18:40

    You use either WebBrowser.DeocumentText (http://msdn.microsoft.com/en-us/library/system.windows.forms.webbrowser.documenttext.aspx) or WebBrowser.DocumentStream (http://msdn.microsoft.com/en-us/library/system.windows.forms.webbrowser.documentstream.aspx) to change the HTML in the current document. You might need to navigate to about:blank, if you don't have a document.

    0 讨论(0)
提交回复
热议问题