0

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?

4

1 回答 1

7

听起来您需要在此处部署可用的其他文件(dll?)。

最好的选择(也是大多数人所做的)是使用System.Net.WebClient之类的东西来下载源代码,然后再次使用 WebClient 来下载图像。

如果您决定使用 HTML 接口IHTMLDocument2,则包含此接口的文件位于其中C:\Program Files (x86)\Microsoft.NET\Primary Interop Assemblies\Microsoft.mshtml.dll (如果您运行的是 32 位 Windows,则不包含 x86)。如果您使用的是 VS 部署项目,请将此文件包含在您的项目中(或手动将其复制到正在运行的应用程序目录)。

于 2011-08-28T03:57:17.963 回答