哪里是IHTMLScriptElement? [英] where is IHTMLScriptElement?

查看:816
本文介绍了哪里是IHTMLScriptElement?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚开始今天使用Visual Studio 2010的C#IDE。

I just started using Visual Studio 2010 C# IDE today.

我想注入的JavaScript web浏览器组件,随后从计算器的回答:

I'm trying to inject javascript to WebBrowser component and followed the answer from stackoverflow:

<一个href="http://stackoverflow.com/questions/153748/how-to-inject-javascript-in-webbrowser-control/154496#154496">How在WebBrowser控件注入Javascript的?

HtmlElement txtBox = webBrowser1.Document.GetElementById("UserEmailShortcut");
//js
HtmlElement scriptOne = webBrowser1.Document.CreateElement("script");
IHTMLScriptElement element = (IHTMLScriptElement)scriptOne.DomElement;
element.text = "function sayHello() { alert('hello') }";
txtBox.AppendChild(scriptOne);
webBrowser1.Document.InvokeScript("sayHello");

现在有下红色波浪线 IHTMLScriptElement 说:

Now there is red wavy line under IHTMLScriptElement saying:

 Error  1   The type or namespace name 'IHTMLScriptElement' 
could not be found (are you missing a using directive or an assembly reference?)
    C:\Users\m-tak\documents\visual studio
 2010\Projects\winformWithWebBrowserTest\winformWithWebBrowserTest\Form1.cs
    25  13  winformWithWebBrowserTest

我看了文档 <一href="http://msdn.microsoft.com/en-us/library/aa768904(v=VS.85).aspx">http://msdn.microsoft.com/en-us/library/aa768904(v=VS.85).aspx

I've looked documentation http://msdn.microsoft.com/en-us/library/aa768904(v=VS.85).aspx

但我想不出为什么。这难道不已经包括在内,只需要包括像使用IHTMLScriptElement (没有工作..)

but I can't figure why. Isn't this already included and just need to include like "using IHTMLScriptElement" (which didn't work..)

推荐答案

项目+添加引用,选择Microsoft.mshtml。如果它没有出现在列表中(这是一个PIA),然后使用浏览选项卡,选择C:\ WINDOWS \ SYSTEM32 \ MSHTML.tlb的

Project + Add Reference, select Microsoft.mshtml. If it doesn't appear in the list (it is a PIA) then use the Browse tab and select c:\windows\system32\mshtml.tlb

添加using指令在源$ C ​​$ C文件的顶部:

Add a using directive at the top of the source code file:

using mshtml;

要小心,你有一个部署细节。如果在目标机器,这不是不可能安装的PIA,然后做的最好的事情就是装配基准为True的复制本地属性设置。这会在build文件夹中Microsoft.mshtml.dll文件。复制它,随着你的EXE文件到目标机器。有其中PIA需要少数情况下,没有这一条。

Beware that you have a deployment detail. If the PIA isn't installed on the target machine, which is not unlikely, then the best thing to do is to set the Copy Local property of the assembly reference to True. That creates the Microsoft.mshtml.dll file in the build folder. Copy it, along with your EXE onto the target machine. There are a few cases where a PIA is required, not this one.

更新到旧帖子,.NET 4+和VS2010 +现在支持嵌入互操作类型参考组装性能。也被称为无PIA功能。这个废弃需要PIA的,是卓越的方式来处理互操作程序集。它会自动设置为True,除非你的项目开始了对旧版本的VS的。

Update to this old post, .NET 4+ and VS2010+ now support the "Embed Interop Types" reference assembly property. Also known as the "No PIA" feature. This obsoletes the need for PIAs and is the superior way to deal with interop assemblies. It is set to True automatically, unless your project got started on an old version of VS.

它没有下侧,你不再需要部署使用interop程序集和互操作类型现在都嵌入到可执行文件。只是那些你使用。一个小小的改变可能需要在code,如果你现在创建COM对象新XxxxClass(),那么你需要删除的类部分名字。

It has no down-sides, you no longer have to deploy the interop assembly and the interop types you use are now embedded in your executable file. Just the ones you use. A small change might be required in your code, if you now create the COM object with new XxxxClass() then you need to remove the "Class" part of the name.

这篇关于哪里是IHTMLScriptElement?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆