从网页浏览器获取图片到图片框
我在图片框中显示一些图片(多于一张)时遇到问题。
<div id="salary_total" style="display: block;"><table style="border: 3px solid rgb(71, 5, 6); padding-right: 1px;" bgcolor="#ffffff" cellpadding="0" cellspacing="0"><tbody><tr><td><img src="./images/counter/b.gif"></td>
<td><img src="./images/counter/3.gif" border="0"></td>
<td><img src="./images/counter/3.gif" border="0"></td>
<td><img src="./images/counter/0.gif" border="0"></td>
<td><img src="./images/counter/8.gif" border="0"></td>
</tr></tbody></table>
那些图片链接,显示为像 3308 这样的数字,并且每次页面加载时它都会改变。如何在图片框中显示这些图片(彼此相邻)。
Try
Dim htmlDocument As HtmlDocument = Me.WebBrowser1.Document
Dim htmlElementCollection As HtmlElementCollection = htmlDocument.Images
For Each htmlElement As HtmlElement In htmlElementCollection
Dim imgUrl As String = htmlElement.GetAttribute("src")
If imgUrl.Contains("counter") Then
Me.PictureBox1.ImageLocation = imgUrl.Substring(0, 41)
End If
Next
这个适用于第一张图片,我怎样才能再有 3 个图片框,并对其他 3 张图片做同样的事情?,就像 3.gif 将转到第一个图片框,依此类推?!
I am having a problem displaying some pictures (more than one) in a picturebox.
<div id="salary_total" style="display: block;"><table style="border: 3px solid rgb(71, 5, 6); padding-right: 1px;" bgcolor="#ffffff" cellpadding="0" cellspacing="0"><tbody><tr><td><img src="./images/counter/b.gif"></td>
<td><img src="./images/counter/3.gif" border="0"></td>
<td><img src="./images/counter/3.gif" border="0"></td>
<td><img src="./images/counter/0.gif" border="0"></td>
<td><img src="./images/counter/8.gif" border="0"></td>
</tr></tbody></table>
those picture links, shows like a number like 3308, and it changes every time the page loads. how can I display those pictures (next to each other) in a picturebox.
Try
Dim htmlDocument As HtmlDocument = Me.WebBrowser1.Document
Dim htmlElementCollection As HtmlElementCollection = htmlDocument.Images
For Each htmlElement As HtmlElement In htmlElementCollection
Dim imgUrl As String = htmlElement.GetAttribute("src")
If imgUrl.Contains("counter") Then
Me.PictureBox1.ImageLocation = imgUrl.Substring(0, 41)
End If
Next
This one works for the first picture, how can I have like 3 more pictureboxs, and do the same for the other 3 pictures?, like the 3.gif will go to the 1st picturebox, and so on?!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我想通了:这就是解决方案!谢谢
I figured it out: Here is the solution! Thanks
首先,您的 ImageLocation 将如下所示:
这可能不是您想要的。
其次,Shoban 说你应该使用常规文本和 CSS。他是对的。
第三,如果要在单个图片框中显示多个图像,则需要创建一个图像对象并将其他图像绘制到其中。有用于此目的的 VB.Net 函数以及本机 Windows API(CopyRect?)。
如果您愿意,可以使用多个图片框。
First, you ImageLocation will come out like this:
That's probably not what you intended.
Second, Shoban said that you should be using regular text and CSS. He's right.
Third, If you want to display multiple images in a single picturebox, you will need to make a single image object and draw the other images into it. There are VB.Net functions for that and also native Windows API (CopyRect?).
You can use multiple picture boxes if you like.