VB - 带有html元素的列表框。 [英] VB - listbox with html element.

查看:78
本文介绍了VB - 带有html元素的列表框。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以给我一些建议吗?我目前有一个我正在使用的列表框,在列表框中有一个来自任何网站的图像列表。它们是通过这种方法从网站上获取的;;;





Can anyone offer me some advise? I currently have a listbox i am using, in the listbox there is a list of images from any website. they are grabbed from the website via this method;;;


Private Sub WebBrowser1_DocumentCompleted(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
    Dim PageElements As HtmlElementCollection = WebBrowser1.Document.GetElementsByTagName("img")
    For Each CurElement As HtmlElement In PageElements
        imagestxt.Items.Add(imagestxt.Text & CurElement.GetAttribute("src") & Environment.NewLine)
    Next
    Timer1.Enabled = True
End Sub





然后我使用图片控制方法来获取图像并显示它。



I then use the picture control method to get the image and display it.

pic1.Image = New System.Drawing.Bitmap(New IO.MemoryStream(New System.Net.WebClient().DownloadData(imagestxtimagestxt.SelectedItem.ToString))).SelectedItem.ToString)))



此方法从HTML中提取图像和标题。






This method pulls the images and title from the HTML.


Private Function StrHTML12() As Boolean
    Dim htmlDocument As HtmlDocument = WebBrowser1.Document
    ListBox1.Items.Clear()
    For Each element As HtmlElement In htmlDocument.All
        ListBox1.Items.Add(element.TagName)
        If element.TagName.ToUpper = "IMG" Then
            imgtags.Items.Add(element.OuterHtml.ToString)
        End If
        If element.TagName.ToUpper = "TITLE" Then
            titletags.Items.Add(element.OuterHtml.ToString)
            Timer1.Enabled = False
        End If
    Next
End Function





这个是一种计算方法来计算多少空的alt =或者很多



基本上我想做的是;



1)有一个程序可以检查图像,看看alt =''''或< img alt =''''如果在网站上开发者没有放入任何东西alt标签我希望图像显示在一个图片框中,我想要在它旁边的alt标签或者它或者什么不足。但我不知道如何。



This is a counting method to count how many empty alt="" or emply

Basicly what i am looking to do is;

1) Have a program that can check the image, look at the alt = '' '' or <img a l t = '' '' if on the website the dev hasn''t put anything in the alt tag i want the image to show in a picture box and i want the alt tag either next to it or underneith it or something. but i have no idea how.

推荐答案

确定..首先创建一个包含所需数据的对象:



OK .. first create an object that holds the data you want:

Public Class HTMLImages
    Public Image As Image
    Public Description As String
    Public Overrides Function ToString() As String
        Return Description
    End Function
End Class





Th用填充的对象填充列表



确保ListBox.DrawMode设置为DrawMode.OwnerDrawFixed



处理ListBox1.DrawItem



如果项目是HTMLImages对象,请绘制您想要的内容



如果你需要GDI +绘画的帮助,请问我



Then populate your list with the filled objects

Make sure your ListBox.DrawMode is set to DrawMode.OwnerDrawFixed

Handle the ListBox1.DrawItem

Paint what you want if the item is a HTMLImages object

If you need help with GDI+ painting ask me


这篇关于VB - 带有html元素的列表框。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆