Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to show html contents with a RichTextBox?

I want to show html contents in my form. I tried to it with rich text box.

rtBox.Text = body;

but it fails.

How to show html contents in RichTextBox? I am using VS 2008.

like image 213
Royson Avatar asked Apr 13 '10 08:04

Royson


People also ask

Can RichTextBox display HTML?

Presents code to display bindable HTML text in a WPF RichTextBox or a WebBrowser.

How do you add a rich TextBox in HTML?

In the Content Type Builder page, add the Rich Text Editor (RTE) field to it. In the Edit Properties section of the RTE field, under Editor Version, select Latest. Under the Editor Type, select Custom, and choose the formatting options you want to include in the RTE field.

What is difference between RichTextBox and TextBox?

For example, editing a document, article, or blog that requires formatting, images, etc is best accomplished using a RichTextBox. A TextBox requires less system resources than a RichTextBox and it is ideal when only plain text needs to be edited (i.e. usage in forms).


2 Answers

If you've got HTML content, you could use the WebBrowser control - otherwise you will have to convert the HTML to RTF to render in the RichTextBox

like image 59
Rowland Shaw Avatar answered Sep 24 '22 20:09

Rowland Shaw


Use a hidden WebBrowser Control and load it with the html content you want. Then SelectAll() from the WebBrowser, Copy(), and Paste() into the richtextbox.

WebBrowser wb = new WebBrowser(); wb.Navigate("about:blank");
string url=@"http:\\....";
wb.Navigate(url);
private const int sleepTimeMiliseconds = 200;

while (wb.ReadyState != WebBrowserReadyState.Complete)
{
Thread.Sleep(sleepTimeMiliseconds);
Application.DoEvents();
}

wb.Document.ExecCommand("SelectAll", false, null);
wb.Document.ExecCommand("Copy", false, null);
richtextbox.Paste();
like image 23
Jerry Avatar answered Sep 24 '22 20:09

Jerry