首先,为您的项目添加对Microsoft.mshtml
的引用,或者如果它不在列表中,则文件为C:\Program Files (x86)\Microsoft.NET\Primary Interop Assemblies\Microsoft.mshtml.dll
。然后,C#代码看起来是这样的:
string myId = "foo";
string myNewValue = "This goes in the Text Area!";
IHTMLDocument2 htmlDoc = webBrowser1.Document.DomDocument as IHtmlDocument2;
if (htmlDoc != null)
{
var textAreaType = typeof(IHTMLTextAreaElemnt);
IHTMLTextAreaElement htmlTextArea =
htmlDoc.All
.FirstOrDefault(x => textAreaType.IsAssignableFrom(x)
&& ((IHTMLElement)x).id == myId)
as IHTMLTextAreaElement;
if (htmlTextArea != null)
{
htmlTextArea.value = myNewValue;
}
}
谢谢埃里克,但你可以指定C#和代码,为我增加了从Microsoft.mshtml.tlb refrence不是微软\ Windows \ System32' 下。。 '.. \ Microsoft Visual Studio 10.0 \ Visual Studio Tools for Office \ PIA \ Common文件夹中的mshtml.dll。 – Murthy 2012-03-18 09:31:42
我已根据您的评论更新。 – 2012-03-18 09:44:46
谢谢你的帮助Erik,但是在添加IHTMLDocument2的引用之后,它仍然显示错误“无法找到类型或名称空间名'IHTMLTextAreaElement'(你是否缺少using指令或程序集引用?)”,我需要安装任何SDK的?或者除了HTML文档之外还有其他方法吗? – Murthy 2012-03-18 10:00:29