In general way .net programmers use the built-in web browser control to display the HTML format content in the windows applications.it is very simple to do.But the web browser control visual appearance (font wise) is not same as the windows controls (Label,Rich Text Box) appearance.we never get windows font look using web browser control because always there is difference between web and windows visualization.
To over come this apply the simple trick here.
var webBrowser = new WebBrowser();
webBrowser.CreateControl(); // only if needed
webBrowser.DocumentText = "
while (webBrowser.DocumentText != "
Application.DoEvents();
webBrowser.Document.ExecCommand("SelectAll", false, null);
webBrowser.Document.ExecCommand("Copy", false, null);
richTextBox1.Paste();
richTextBox1.ReadOnly = true;
ExecCommand() executes a command on the current document,/current selection/ the given range.
To over come this apply the simple trick here.
- Place the rich text box control in the form.
- Create the Web Browser control form the code behind
- Bind the html content to web browser.
- Select and copy the html content Using the HTML document ExecCommand()
- Paste content to rich text box using the paste() method of Rich text box
var webBrowser = new WebBrowser();
webBrowser.CreateControl(); // only if needed
webBrowser.DocumentText = "
<html><body><b>DotnetCyphers
</b></body></html>";
while (webBrowser.DocumentText != "
<html><body><b>DotnetCyphers
</b></body></html>
")Application.DoEvents();
webBrowser.Document.ExecCommand("SelectAll", false, null);
webBrowser.Document.ExecCommand("Copy", false, null);
richTextBox1.Paste();
richTextBox1.ReadOnly = true;
ExecCommand() executes a command on the current document,/current selection/ the given range.
No comments:
Post a Comment