IHTMLDocument2 并非在所有地方都适用
在 winform 应用程序中,我有 WebBrowser
控件和 PictureBox
。我正在使用下面的代码将图像(从 DocumentComplete
之后的网络浏览器控件)加载到 pictureBox1
IHTMLDocument2 doc = (IHTMLDocument2)webBrowser1.Document.DomDocument;
IHTMLControlRange imgRange = (IHTMLControlRange)((HTMLBody)doc.body).createControlRange();
foreach (IHTMLImgElement img in doc.images)
{
imgRange.add((IHTMLControlElement)img);
imgRange.execCommand("Copy", false, null);
pictureBox1.Bitmap = (Bitmap)Clipboard.GetDataObject().GetData(DataFormats.Bitmap);
}
图像显示在我电脑上的 picturebox1 中,但不在我朋友的电脑上。在另一个Windows XP上安装VS2008后运行良好。所以我猜 IHTMLDocument2 需要 Windows 更新才能正常工作。
那是哪个更新?或者此代码的任何其他替代方案,我不必从互联网重新下载图像?
In a winform application I have WebBrowser
control and a PictureBox
. I am loading an Image (from webbrowser control after DocumentComplete
) to pictureBox1 with the code below
IHTMLDocument2 doc = (IHTMLDocument2)webBrowser1.Document.DomDocument;
IHTMLControlRange imgRange = (IHTMLControlRange)((HTMLBody)doc.body).createControlRange();
foreach (IHTMLImgElement img in doc.images)
{
imgRange.add((IHTMLControlElement)img);
imgRange.execCommand("Copy", false, null);
pictureBox1.Bitmap = (Bitmap)Clipboard.GetDataObject().GetData(DataFormats.Bitmap);
}
Image is displayed in picturebox1 on my pc, but not on my friend's. On another windows XP it worked well after installing VS2008. So I guess IHTMLDocument2 needs a windows update to work correctly.
Which update is that? Or any other alternative to this code in which i don't have to redownload image from internet?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
听起来您需要部署其他可用的文件(dll?)此处。
最好的选择(以及什么)大多数人都会这样做)是使用类似 System.Net.WebClient 下载源码,然后再次使用WebClient 下载镜像。
如果您确定使用 HTML
IHTMLDocument2
接口,则包含此接口的文件位于C:\Program Files (x86)\Microsoft.NET\Primary Interop Assemblies\Microsoft.mshtml 中。 dll
(如果您运行的是 32 位 Windows,则无需 x86)。如果您使用 VS 部署项目,请将此文件包含在您的项目中(或手动将其复制到正在运行的应用程序目录)。Sounds like you need to deploy additional files (dlls?) available Here.
The best option (and what most people do) is to use something like System.Net.WebClient to download the source, and the use WebClient again to download the image.
If you are determined to use an interface for HTML
IHTMLDocument2
the file that contains this interface is inC:\Program Files (x86)\Microsoft.NET\Primary Interop Assemblies\Microsoft.mshtml.dll
(without the x86 if you are running 32-bit Windows). Include this file in your project if you are using a VS Deployment project (or copy it to the running application directory manually).