Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27513

VS 2010 Writing text/HTML to WebBrowser control

$
0
0
I am working on a basic web page editor using mshtml.dll and a WebBrowser control. I want to switch between "design view" and "code view" - the latter showing the HTML tags etc. I can copy the HTML to a textbox to produce the code view and it works fine. Copying the HTML back to the WebBrowser control (allowing the user to make edits to the HTML tags and then show those changes in "design view") is not working properly. After a few clicks between design view and code view, the contents of the WebBrowser control start being duplicated. One line of text becomes two, then four, then eight etc.

Here is some of my code.

Initialisation:

Code:

Imports mshtml

    Dim Mdoc As IHTMLDocument2

        wb1.DocumentText = "<html><body></body></html>"
        Mdoc = wb1.Document.DomDocument
        Mdoc.designMode = "On"

Design view - code view switching:

Code:

            If optEditor.Checked Then
                wb1.Visible = True
                txtHTML.Visible = False
                wb1.Document.Write(txtHTML.Text)
            Else
                wb1.Visible = False
                txtHTML.Visible = True
                txtHTML.Text = wb1.DocumentText
            End If

I guess I need to clear something before writing txtHTML.Text into the WebBrowser control, but I can't seem to find what it is.

Any help would be much appreciated.

Viewing all articles
Browse latest Browse all 27513

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>