|
-
Dec 16th, 2012, 05:48 PM
#1
Thread Starter
Fanatic Member
[RESOLVED] Writing text/HTML to WebBrowser control
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.
-
Dec 16th, 2012, 05:55 PM
#2
Re: Writing text/HTML to WebBrowser control
wb1.Document.Write(txtHTML.Text)
This is append by default so set .DocumentText = "" immediately before it to avoid repetition (assuming you will be writing the whole document on each occasion).
As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"
Reviews: "dunfiddlin likes his DataTables" - jmcilhinney
Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!
-
Dec 16th, 2012, 06:19 PM
#3
Thread Starter
Fanatic Member
Re: Writing text/HTML to WebBrowser control
Doesn't work I'm afraid. The WebBrowser control goes blank and is not editable any more (no cursor appears when you click it). It's as if the tags get screwed up. I tried adding wb1.DocumentText = "<html><body></body></html>" after setting it to nothing but it still doesn't work.
-
Dec 16th, 2012, 07:30 PM
#4
Re: Writing text/HTML to WebBrowser control
No, you're right it doesn't. This, however, does (well for me anyway)
wb1.Document.OpenNew(False)
wb1.Document.Write(txtHTML.Text)
As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"
Reviews: "dunfiddlin likes his DataTables" - jmcilhinney
Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!
-
Dec 17th, 2012, 12:18 AM
#5
Thread Starter
Fanatic Member
Re: Writing text/HTML to WebBrowser control
 Originally Posted by dunfiddlin
No, you're right it doesn't. This, however, does (well for me anyway)
wb1.Document.OpenNew(False)
wb1.Document.Write(txtHTML.Text)
That is just perfect! Many thanks.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|