In the past two days, a function is provided to display the text in html of the captured webpage in richtextbox in the format. However, richtextbox does not recognize html tags. I plan to write an html interpreter myself, but it takes too much time. Since it is a small function, find a shortcut. I thought of two methods.
1. richtextbox is no longer needed and is directly displayed in webbrowser.
Since richtextbox does not recognize html, WebBrowser should always recognize it. Replace richtextbox with WebBrowser.
[Csharp]
String testString = @ "<FONT face = Verdana>
<P> <FONT face = Verdana> test content: </FONT> </P>
<P> <FONT face = Verdana> Haha <BR> dinner <BR> off duty <BR> go home <BR> sleep </FONT> </P>
<P> <FONT face = Verdana> heheh <BR> Shenma </FONT> </P>
<P> <FONT face = Verdana> <BR> </FONT> </P> </FONT>
<P> <FONT face = Verdana> <BR> </FONT> </P> </FONT> ";
WebBrowser1.DocumentText = testString;
// However, it seems that the insurance should be a little bit more.
WebBrowser1.Document. Write (testString );
WebBrowser1.Refresh ();
String testString = @ "<FONT face = Verdana>
<P> <FONT face = Verdana> test content: </FONT> </P>
<P> <FONT face = Verdana> Haha <BR> dinner <BR> off duty <BR> go home <BR> sleep </FONT> </P>
<P> <FONT face = Verdana> heheh <BR> Shenma </FONT> </P>
<P> <FONT face = Verdana> <BR> </FONT> </P> </FONT>
<P> <FONT face = Verdana> <BR> </FONT> </P> </FONT> ";
WebBrowser1.DocumentText = testString;
// However, it seems that the insurance should be a little bit more.
WebBrowser1.Document. Write (testString );
WebBrowser1.Refresh ();
2. richtextbox must be displayed for some reasons.
In this case, we have to use a nondescribedomainmethod. Or use WebBrowser.
[Csharp]
String testString = @ "<FONT face = Verdana>
<P> <FONT face = Verdana> test content: </FONT> </P>
<P> <FONT face = Verdana> Haha <BR> dinner <BR> off duty <BR> go home <BR> sleep </FONT> </P>
<P> <FONT face = Verdana> heheh <BR> Shenma </FONT> </P>
<P> <FONT face = Verdana> <BR> </FONT> </P> </FONT>
<P> <FONT face = Verdana> <BR> </FONT> </P> </FONT> ";
Using (WebBrowser webBrowser = new WebBrowser ())
{
WebBrowser. Visible = false;
WebBrowser. DocumentText = testString;
WebBrowser. Document. Write (testString );
This. richTextBox1.Text = webBrowser. Document. Body. OuterText;
}
String testString = @ "<FONT face = Verdana>
<P> <FONT face = Verdana> test content: </FONT> </P>
<P> <FONT face = Verdana> Haha <BR> dinner <BR> off duty <BR> go home <BR> sleep </FONT> </P>
<P> <FONT face = Verdana> heheh <BR> Shenma </FONT> </P>
<P> <FONT face = Verdana> <BR> </FONT> </P> </FONT>
<P> <FONT face = Verdana> <BR> </FONT> </P> </FONT> ";
Using (WebBrowser webBrowser = new WebBrowser ())
{
WebBrowser. Visible = false;
WebBrowser. DocumentText = testString;
WebBrowser. Document. Write (testString );
This. richTextBox1.Text = webBrowser. Document. Body. OuterText;
}
In this way, the plain text content can be obtained for separate processing and application in other places.
The result is as follows:
Note:
1. Here webBrowser. Document. Write is used, because webBrowser. DocumentText = testString is null and cannot be used for text;
2. The process is slow;
From Poplar