我将VB.Net
应用转移到了C#
,当我构建它时。出现此错误 -
'mshtml.IHTMLImgElement'不包含。的定义 'getattribute'并没有扩展方法'getattribute'接受a 可以找到类型'mshtml.IHTMLImgElement'的第一个参数(是 你错过了使用指令或程序集引用?)
那么如何更换此getattribute
来电?
这是代码
private void captcha()
{
mshtml.IHTMLDocument2 doc = (mshtml.IHTMLDocument2) WebBrowser1.Document.DomDocument;
mshtml.IHTMLControlRange imgrange = (mshtml.IHTMLControlRange) (((mshtml.HTMLBody) doc.body).createControlRange());
foreach (mshtml.IHTMLImgElement img in doc.images)
{
if (img.getattribute("src").ToString().Contains("urltoimg"))
{
imgrange.add((mshtml.IHTMLControlElement) img);
imgrange.execCommand("copy", false, null);
PictureBox1.Image = (System.Drawing.Image) (Clipboard.GetDataObject().GetData(DataFormats.Bitmap));
break;
}
}
}
答案 0 :(得分:0)
尝试“GetAttribute”。 VB不区分大小写,因此“getattribute”可以在VB中运行,但是C#(以及几乎所有其他语言)都区分大小写。
答案 1 :(得分:0)
您需要将mshtml.IHTMLImgElement
转换为mshtml.IHTMLElement
,然后会为您提供getAttribute()
方法
您可以将此行替换为:
if (((mshtml.IHTMLElement)img.getAttribute("src")).ToString().Contains("urltoimg"))
请注意外壳为'getAttribute',而不是'getattribute'。