I'm trying to make a picture's visibility toggle on a timer. The picture I am trying to change is underscore(i). Here is that code:
Dim DigitSelected As Integer = 1
Public Underscores(3) As PictureBox
Private Sub CursorTimer_Tick(sender As System.Object, e As System.EventArgs) Handles CursorTimer.Tick
Me.Underscores(DigitSelected).Visible = Not (Me.Underscores(DigitSelected).Visible)
For i As Byte = 1 To 3
.Underscores(i) = New PictureBox
.Height = 60
.Width = 144
.ImageLocation = "Underscore.png"
.BackColor = Color.Transparent
I don't exactly know what you are trying to achieve here, but here is what happens :
Everytime you run that loop, you create three transparent PictureBox that you add to your Main Form. You don't remove anything, nor hide anything !
If you want to toggle visibility, that is no way of doing so !
The best would be for you to know the PictureBoxes names, so you can do :
Dim pb1 = CType(Initials.FindControl("MyPictureBox", true), PictureBox) If Not IsNothing(pb1) Then pb1.Visible = Not pb1.Visible End If