将图像添加到列表框(Visual Basic) [英] add images to listbox (visual basic)

查看:95
本文介绍了将图像添加到列表框(Visual Basic)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有几组网络托管图片,我需要我的用户能够从每张图片中选择1张.我以为有一个列表框可以解决这个问题,但是我不知道将图像添加到其中.这可能吗?更好的方法吗?我正在使用最新的免费vb.

I have sets of web hosted images that I need my user to be able to select 1 from each. I thought a listbox would work for this, but I can't figure out add an image to one. Is this possible? better way of doing this? I am using the latest free vb.

推荐答案

使用 Listview控件,它提供了更好的功能,并且没有烦人的调整大小错误.列表框从VB6天开始被保留.列表视图支持列标题,分组等等.

Use the Listview control instead, it provides better functionality, and doesn't suffer from an annoying resize bug. The listbox is carried over from VB6 days. The listview supports column headers, groupings and a bit more.

向您的表单添加一个图像列表控件,以存储图像;将其ColorDepth属性设置为32位,并将Listview的LargeImagelist属性设置为刚添加的imagelist控件(这也可以用代码完成).

Add a Imagelist control to your form, to store the images; set it's ColorDepth property to 32-bit, and set the Listview's LargeImagelist property to the imagelist control you just added (this can all be done in code as well).

通过以下代码将图像添加到图像列表:

Add images to the Imagelist via this code:

ImageList1.Images.Add("imagekey", Image.FromStream(yourimagestream))

通过以下代码将项目添加到Listview:

Add items to the Listview via this code:

ListView1.Items.Add("list item title", "imagekey")

"imagekey"是一种告诉Listview要使用哪个图像的方法.您也可以为图标使用索引,但是指定不存在的索引将给出索引超出范围的异常,而不存在的键将仅不使用图像.

The "imagekey" is a way to tell the Listview which image to use. You can also use indexes for icons, but specifying an index that doesn't exist will give an index out of range exception, whereas a key that doesn't exist, will just use no image instead.

哦,您还想将Listview Multiselect属性设置为False(如果您只希望它们一次选择一个),并在用户单击/双击时访问SelectedIndexChanged()和ItemActivate()事件.项.

Oh you also want to set the Listview Multiselect property to False (if you only want them to select one at a time), and access the SelectedIndexChanged() and ItemActivate() events for when the user clicks / double-clicks on items respectively.

这篇关于将图像添加到列表框(Visual Basic)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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