Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/EmptyTag/160.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vb.net 如果单击按钮,Picturebox将更改_Vb.net_Picturebox - Fatal编程技术网

Vb.net 如果单击按钮,Picturebox将更改

Vb.net 如果单击按钮,Picturebox将更改,vb.net,picturebox,Vb.net,Picturebox,大家好,我想问一下,如果我点击了一个按钮,我有一个图片框和一个按钮,Button1,我想每次点击Button1,我都要改变图片。提前感谢:)在按钮单击事件中,您可以添加以下内容 PictureBox1.Image= Image.FromFile("c:\folder\file.gif") 将路径替换为所需的图像 编辑 要每次更改它,您需要创建一个全局变量“counter”。 每次单击时添加该值 另外,创建一组图片 因此,每次单击时,您都会在数组中选择索引为counter的字符串,并将其设置为上

大家好,我想问一下,如果我点击了一个按钮,我有一个图片框和一个按钮,
Button1
,我想每次点击
Button1
,我都要改变图片。提前感谢:)

在按钮单击事件中,您可以添加以下内容

PictureBox1.Image= Image.FromFile("c:\folder\file.gif")
将路径替换为所需的图像

编辑

要每次更改它,您需要创建一个全局变量“counter”。 每次单击时添加该值

另外,创建一组图片

因此,每次单击时,您都会在数组中选择索引为counter的字符串,并将其设置为上述代码中的图像

Dim array() As String = {"c:\folder\file1.gif", "c:\folder\file2.gif", "c:\folder\file3.gif"}

PictureBox1.Image= Image.FromFile(array(counter))

您可以创建包含在
Somefilepath中的
图像的
列表

Dim images As New List(Of Image)()
images.add(Image.FromFile(Somefilepath))
Dim imageindex as Integer 

imageIndex = 0
现在,在一个单独的功能中,您可以在每次单击
按钮1
时更改图片

  Private Sub Button1_Click(sender As Object, e As EventArgs)

    PictureBox1.Image = images(imageIndex)
    imageIndex = imageIndex + 1
End Sub

这只会在第一次单击“Button1”时更改图像。现在您需要逐个写入每个路径。无论以何种方式,您都需要付出巨大的努力来指定路径。在文件、表格或代码中。另一种方法是基于上一张图像使其动态化。但是这个问题来自于一个新加入编程Devcon 2的人,我想从心底感谢你:)你的两个答案都起作用了,我试过了,但你的答案更适合像我这样的新手……再次感谢你和equisdeHi先生,先生,你能详细说明这个过程吗?我刚刚开始编程:(提前感谢:)
images
是包含在Somefilepath中的图像列表。您可以将
Somefilepath
替换为包含要显示的图像的文件夹的路径
imageIndex
是一个索引,它从0开始,每次单击按钮时都会自动递增,因此当您单击按钮时,图像会发生更改,索引将放置在下一个要显示的图像中