简体   繁体   中英

IHTMLDocument2 does not work everywhere

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?

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 in C:\\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).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM