Microsoft Communities

Welcome to WindowsClient.net | Sign in | Join

Here are some frequently asked questions about Windows Forms and their answers.

Windows Forms FAQs

How do I enable editing in a WebBrowser?

You can set the content editable by getting a reference to a IHTMLElement3 element and initializing the contentEditable property with "true".

private void EnableEditing()
{
  IHTMLDocument3 doc = (IHTMLDocument3) browser.GetDocument();
  if (doc != null)
  {
    IHTMLElement3 el = (IHTMLElement3) doc.GetBody();
    el.contentEditable = "true";
  }
}

If you want to read out contents of a specific element use an id in the html source:

<span id="EditText">EditableText</span>

From C# you can reference this text with

IHTMLElement3 el = (IHTMLElement3) doc.getElementById("EditText");
MessageBox.Show(el.GetInnerText());
MessageBox.Show(el.GetInnerHTML());

You can use IHTMLDocument3 and IHTMLElement3 interface definitions from the imported type library dll C:\Program Files\Microsoft.NET\Primary Interop Assemblies\Microsoft.mshtml.dll

Contributed from George Shepherd's Windows Forms FAQ



Page view counter