質問

Hi good day guys i would just like to ask if how can I change a picture in a PictureBox if I clicked a button to be specific i have one picture box and one button which is Button1 and I want to change the picture everytime I click the Button1. Thanks in advance :)

役に立ちましたか?

解決

In your button1_click event, you could add the following

PictureBox1.Image= Image.FromFile("c:\folder\file.gif")

Replace the path with the image you need.

EDIT

To change it everytime, you need to create a global variable 'counter'. Add to that value everytime you click.

Also, create an array of pictures.

So everytime you click, you select the string in the array with the index of counter and you set that as the image in the code presented above.

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

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

他のヒント

You can create a List of Image contained into Somefilepath

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

imageIndex = 0

Now in a separate function you can change your pictures every time the Button1 is clicked

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

    PictureBox1.Image = images(imageIndex)
    imageIndex = imageIndex + 1
End Sub
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top