如何使用数组vb.net将picturebox图像的值传递给另一个图片框

时间:2018-05-15 17:29:01

标签: arrays database vb.net access

我是vb.net的初学者,请帮助我 如何将picturebox1.image传递给picturebox2.image,将picturebox2.image的值传递给picturebox3.image。我的观点是,每当新图像到达时,就像图像向前移动一样。传入的图像将转到picturebox1。而picturebox1的旧值将移至picturebox2,picturebox2的值将转到picturebox3。我不知道如何在编码中构造逻辑。请帮帮我

1 个答案:

答案 0 :(得分:0)

好的,有很多方法可以实现这一目标。我使用我的数据库一直存储图像,因此我将向您展示一种按照从数据库中检索图像的顺序显示图像的方法。你是正确的,如果你将pic2.image分配给pic1.image等,图片框将都具有相同的图像,因为它是pic1的值,反转顺序做同样的事情。您需要将每个图片框中所需的图像分配给该图片框。

首先,我创建一个图像列表,它们都是jpg'但它不应该重要:

Imports System.Drawing ' <---- I assume you have this at the top of the code behind
Dim MyImages as List(of Image) 

我按照主键升序的顺序从数据库中检索数据库中的图像,键是1到n并填充列表:

Dim x as Integer = 1
pictureboxname = "pic" & x
For Each MyDataRow as DataRow in MyTable.Rows
    ' Load the list, the image is in column zero
    MyImages.Add(MyDataRow(0))
    ' because this is the initial list, you can also populate the pictureboxes too
    ' you need to use the picturebox name in an expression to populate the pictureboxes in a loop.
    ' Something like this .... this is untested
    (pictureboxname).Image = MyImages(MyImages.Count -1) 
    ' and change picturebox name to the next picture box
    x += 1
    ' I assume picturebox name is pic1, pic2, etc ....
    pictureboxname = "pic" + x
    ' you'll have to limit this loop to the number of pictureboxes you have if they are less than the number of images, but you get the idea
Next

添加新图像后,您可以同时将其添加到列表和数据库中,然后重新填充图片框。

StoreImage(NewImage)
MyImages.Add(NewImage)

Dim x as integer = 1
pictureboxname = "pic" & x
For each MyImage as Image in MyImages
    ' assign each image in turn to the picture boxes ... again, untested
    (pictureboxname).Image = MyImage
    x += 1
    pictureboxname = "pic" & x
    ' again, you'll have to limit this loop to the number of pictureboxes you have if it is less than the number of images ....
Next

这不是你正在寻找的,但应该让你开始。