I'd like to change the contents of the tag on vb.net, but I can't.
When you first load the form, set "1" to the picturebox1 tag.When the form first appears, picturebox1 displays 1.png.
Then click picturebox1 to determine the conditions of the if statement in PictureBox1_Click function
If Me.PictureBox1.Tag="1" Then
is determined to be true and the picturebox1 image is 2.png.
At this time,
Me.PictureBox1.Image.Tag="2"
I think I set "2" to the picturebox1 tag in
below it.
Debug.WriteLine(Me.PictureBox1.Tag.ToString)
displays 1 in the output window.
The picturebox tag remains "1", so 2.png remains displayed no matter how many times you click it.
Why can I set tag to "1" in the first Form1_Load function, but then I can't change it?
Public Class Form 1
Private Sub PictureBox1_Click(sender As Object, eAs EventArgs) Handles PictureBox1.Click
Debug.WriteLine(Me.PictureBox1.Tag.ToString)' ← No matter how many times I click, I get 1 here.
If Me. PictureBox1.Tag="1" Then
Me.PictureBox1.Image=Image.FromFile("C:\Users\tada3\Desktop\Home Tool\seg\2.png")
Me.PictureBox1.Image.Tag="2"
Debug.WriteLine(Me.PictureBox1.Tag.ToString)' ← I want you to print 2 here, but you get 1
ElseIf Me. PictureBox1.Tag="2" Then
Me.PictureBox1.Image=Image.FromFile("C:\Users\tada3\Desktop\Home Tool\seg\1.png")
Me.PictureBox1.Image.Tag="1"
End If
End Sub
Private SubForm1_Load (sender As Object, eAs EventArgs) Handles MyBase.Load
Me.PictureBox1.Image=Image.FromFile("C:\Users\tada3\Desktop\Home Tool\seg\1.png")
Me. PictureBox1.Tag="1"
End Sub
End Class
PictureBox1.Tag and PictureBox1.Image.Tag were mixed.
It worked properly with the following:
Public Class Form 1
Private Sub PictureBox1_Click(sender As Object, eAs EventArgs) Handles PictureBox1.Click
Debug.WriteLine(Me.PictureBox1.Image.Tag.ToString)' ← No matter how many times I click, I get 1 here.
If Me. PictureBox 1. Image.Tag="1" Then
Me.PictureBox1.Image=Image.FromFile("C:\Users\tada3\Desktop\Home Tool\seg\2.png")
Me.PictureBox1.Image.Tag="2"
Debug.WriteLine(Me.PictureBox1.Image.Tag.ToString)' ← I want you to see 2 here, but 1 appears.
ElseIf Me.PictureBox1.image.Tag="2" Then
Me.PictureBox1.Image=Image.FromFile("C:\Users\tada3\Desktop\Home Tool\seg\1.png")
Me.PictureBox1.Image.Tag="1"
End If
End Sub
Private SubForm1_Load (sender As Object, eAs EventArgs) Handles MyBase.Load
Me.PictureBox1.Image=Image.FromFile("C:\Users\tada3\Desktop\Home Tool\seg\1.png")
Me.PictureBox1.Image.Tag="1"
End Sub
End Class
Thank you.
© 2024 OneMinuteCode. All rights reserved.