If I enable emulation of IE11 for my application in registry here:
HKCU\Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION\myAppName.exe
and insert html into WinForms WebBrowser control using function IHTMLTxtRange.pasteHtml(), then text between html elements is interpreted probably wrong:
-spaces transformed to <p> </p>
-line breaks between html elements transformed to <br/> tags.
As a result I get wrong html.
--------------------------------------------------------------------------------------------------------------------
Test application:
---------------------
Form1.cs:
{
public Form1()
{
//enable IE11 mode
string fileName = System.IO.Path.GetFileName(Process.GetCurrentProcess().MainModule.FileName);
using (RegistryKey key = Registry.CurrentUser.CreateSubKey(
@"Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION",
RegistryKeyPermissionCheck.ReadWriteSubTree))
{
key.SetValue(fileName, (UInt32)11001, RegistryValueKind.DWord);
}
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
//enable design mode
webBrowser1.Navigate("about:blank");
IHTMLDocument2 mshtmlDoc2 = webBrowser1.Document.DomDocument as IHTMLDocument2;
mshtmlDoc2.designMode = "On";
//insert html
while (mshtmlDoc2.readyState != "complete")
{
Application.DoEvents();
}
mshtmlDoc2.body.innerHTML = "<p>paragraph 1</p>";
IHTMLTxtRange bodyRange = (mshtmlDoc2.body as IHTMLBodyElement).createTextRange();
bodyRange.collapse(Start: false);
bodyRange.pasteHTML("<p>paragraph 2</p>\n\n\n <p>paragraph 3</p>");
//show result html
textBox1.Text = webBrowser1.DocumentText;
}
}
----------------
Form1.designer.cs:
partial class Form1{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.webBrowser1 = new System.Windows.Forms.WebBrowser();
this.button1 = new System.Windows.Forms.Button();
this.textBox1 = new System.Windows.Forms.TextBox();
this.SuspendLayout();
//
// webBrowser1
//
this.webBrowser1.Location = new System.Drawing.Point(12, 12);
this.webBrowser1.MinimumSize = new System.Drawing.Size(20, 20);
this.webBrowser1.Name = "webBrowser1";
this.webBrowser1.Size = new System.Drawing.Size(626, 190);
this.webBrowser1.TabIndex = 0;
//
// button1
//
this.button1.Location = new System.Drawing.Point(12, 338);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(143, 23);
this.button1.TabIndex = 1;
this.button1.Text = "Insert html";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(12, 208);
this.textBox1.Multiline = true;
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(626, 124);
this.textBox1.TabIndex = 2;
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(652, 373);
this.Controls.Add(this.textBox1);
this.Controls.Add(this.button1);
this.Controls.Add(this.webBrowser1);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.WebBrowser webBrowser1;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.TextBox textBox1;
}
------------
As a result I get the following html which, I think, is wrong:
<P>paragraph 2</P>
<P><BR><BR><BR> </P>
<P>paragraph 3</P>