?
Solved

Display html in rich text box

Posted on 2003-03-04
8
Medium Priority
?
227 Views
Last Modified: 2013-12-26
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.
0
Comment
Question by:Chaya
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
8 Comments
 
LVL 5

Expert Comment

by:Rhaedes
ID: 8063992
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
 

Author Comment

by:Chaya
ID: 8064300
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
 
LVL 5

Accepted Solution

by:
Rhaedes earned 200 total points
ID: 8064703
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:Chaya
ID: 8070562
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
 

Author Comment

by:Chaya
ID: 8070673
I have found code to do the above (change menu with right click). I'm checking the code now.
0
 

Author Comment

by:Chaya
ID: 8070760
I have found code to do the above (change menu with right click). I'm checking the code now.
0
 
LVL 5

Expert Comment

by:Rhaedes
ID: 8070954
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
 

Author Comment

by:Chaya
ID: 8078356
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

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses
Course of the Month10 days, 1 hour left to enroll

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question