Link to home
Start Free TrialLog in
Avatar of Chaya
Chaya

asked on

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.
Avatar of Rhaedes
Rhaedes

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
Avatar of Chaya

ASKER

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
ASKER CERTIFIED SOLUTION
Avatar of Rhaedes
Rhaedes

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Chaya

ASKER

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
Avatar of Chaya

ASKER

I have found code to do the above (change menu with right click). I'm checking the code now.
Avatar of Chaya

ASKER

I have found code to do the above (change menu with right click). I'm checking the code now.
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

Avatar of Chaya

ASKER

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