Display html in rich text box

What I want is the following:
I have the path of a html file (with text only, no tables pictures etc.). I want to display the text in the rich text box.
The text must be displayed with all the font settings i.e. font color, size, bold etc.
The user can then edit the text (I already have code to save the rich text box as html).
Some ideas how to solve:
1. Alogrithm to analyse the html tags.
2. Load the page into a webbrowser object and the use the document.body.innertext to get the text (doesn't give the text format).

I'll appreciate a clear answer with a working example.
ChayaAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

RhaedesCommented:
Do you really need to use a RichTextBox? If you set the HTML document's designMode property to "on" you can edit text directly in the webbrowser. This is much easier than passing text to and fro between the two formats.

For example, put a webbrowser on a form and add this code:

Private Sub Form_Load()
WebBrowser1.Navigate ("about:blank")
End Sub

Private Sub WebBrowser1_DocumentComplete(ByVal pDisp As Object, URL As Variant)
WebBrowser1.Document.designMode = "On"
End Sub

Obviously, the navigate method loads the file into the webbrowser. To save the file once you've edited it, write the string 'WebBrowser1.Document.All(0).outerHTML' to a file.

Kindest regards,
Rhaedes
0
ChayaAuthor Commented:
Your answer might help me...
Is it possible to allow the user to edit the webbrowser text format i.e. change selected font to bold etc.
I need that the editing of the text will be as flexible as by the rich text box object.
Thanks for the speedy reply
0
RhaedesCommented:
It's very simple. Here's a simple example: Put a webbrowser (WebBrowser1) on a form, with two checkboxes (Check1 and Check2) to turn bold and italics on an off. Add two comboboxes (Combo1 and combo2) for font size and colour. Reference the HTML Object Library and add the code below.
You'll see how it works with the execCommand methods in the code. For a complete list check out http://msdn.microsoft.com/library/default.asp?url=/workshop/author/dhtml/reference/methods/execcommand.asp

Kindest regards,
Rhaedes


Private WithEvents Hdoc As HTMLDocument

Private Sub Check1_Click()
r = Hdoc.selection.createRange
Hdoc.execCommand "Bold", Check1.Value
WebBrowser1.SetFocus
End Sub

Private Sub Check2_Click()
r = Hdoc.selection.createRange
Hdoc.execCommand "Italic", Check1.Value
WebBrowser1.SetFocus
End Sub

Private Sub Combo1_Click()
r = Hdoc.selection.createRange
Hdoc.execCommand "ForeColor", True, Combo1.Text
WebBrowser1.SetFocus
End Sub

Private Sub Combo2_Click()
r = Hdoc.selection.createRange
Hdoc.execCommand "FontSize", True, Combo2.Text
WebBrowser1.SetFocus
End Sub

Private Sub Form_Load()
WebBrowser1.Navigate ("about:blank")

With Combo1
.AddItem "black"
.AddItem "red"
.AddItem "green"
End With

With Combo2
.AddItem "2"
.AddItem "5"
.AddItem "16"
End With

End Sub

Private Sub WebBrowser1_DocumentComplete(ByVal pDisp As Object, URL As Variant)
WebBrowser1.Document.designMode = "On"
Set Hdoc = WebBrowser1.Document
End Sub
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

ChayaAuthor Commented:
Thanks, I tried your code and it works well.
But...
I still have one problem with it:
I want the user to be able to use it like a text editor without realizing it is a webbrowser. I want to know how to cancel the internet popup that comes up with a right click and to display instead my own popup (that has options for changing fonts, bold etc.)
Could you provide me with code for this? I will provide 20 bonus points
0
ChayaAuthor Commented:
I have found code to do the above (change menu with right click). I'm checking the code now.
0
ChayaAuthor Commented:
I have found code to do the above (change menu with right click). I'm checking the code now.
0
RhaedesCommented:
Since Hdoc is declared as withevents, you can trap mouse clicks on the document, and even have different popups depending on the element under the mouse. Basically, use the sub 'Private Sub HDoc_onmousedown()' and chack for a right mouse click using 'If HDoc.parentWindow.event.button = 2 Then...'
You could check out Richie Simon's code at http://www.angelfire.com/realm/vb-shared/IE_WB_DOM_tips.htm#overrwb

Kindest regards,
Rhaedes

0
ChayaAuthor Commented:
You seem to be the expert in webbrowsers. Any chance of help with the following:

1.How can I prevent the user from draging and dropping images from other webbrowser controls
2. How can I cause that some webbrowser controls on the form will have no popup menus and others will have my pop up menu
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.