开发者

IHTMLDocument2 does not work everywhere

开发者 https://www.devze.com 2023-04-01 10:06 出处:网络
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

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 IHT开发者_JS百科MLDocument2 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).

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号