ssoni

Terminator Picture Box array/list

May 18th, 2021
700
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Public Class Form1
  2.     Public terminators(6) As PictureBox
  3.     Public terminatorList As New List(Of PictureBox)
  4.  
  5.     Private Sub lblHide_Click(sender As Object, e As EventArgs) Handles lblHide.Click
  6.         Dim x As Integer
  7.  
  8.         'For x = 0 To terminators.Length - 1
  9.        ' terminators(x).Visible = False
  10.        'Next
  11.  
  12.         Dim p As PictureBox
  13.  
  14.         For Each p In terminatorList
  15.             p.Visible = False
  16.         Next
  17.  
  18.         lblShow.Visible = True
  19.         lblHide.Visible = False
  20.     End Sub
  21.  
  22.     Private Sub lblShow_Click(sender As Object, e As EventArgs) Handles lblShow.Click
  23.         Dim x As Integer
  24.  
  25.         For x = 0 To terminators.Length - 1
  26.             terminators(x).Visible = True
  27.         Next
  28.  
  29.         Dim p As PictureBox
  30.  
  31.         For Each p In terminatorList
  32.             p.Visible = True
  33.         Next
  34.  
  35.         'when you click show, you need to enable the hide feature
  36.        lblHide.Visible = True
  37.         lblShow.Visible = False
  38.     End Sub
  39.  
  40.     Private Sub PictureBoxALL_Click(sender As Object, e As EventArgs) Handles PictureBox1.Click, PictureBox2.Click, PictureBox3.Click, PictureBox4.Click, PictureBox5.Click, PictureBox6.Click, PictureBox7.Click
  41.         Dim p As PictureBox
  42.         p = DirectCast(sender, PictureBox)
  43.         p.Visible = False
  44.  
  45.         'check if all are now hidden
  46.        'if so, disable the Hide command
  47.  
  48.         Dim allHidden As Boolean
  49.         allHidden = True
  50.  
  51.         For Each p In terminatorList
  52.             If p.Visible = True Then
  53.                 allHidden = False
  54.             End If
  55.         Next
  56.  
  57.         If allHidden = True Then
  58.             lblHide.Visible = False
  59.             lblShow.Visible = True
  60.         End If
  61.  
  62.         lblShow.Visible = True
  63.     End Sub
  64.  
  65.     Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  66.  
  67.         'load array
  68.        terminators = {PictureBox1, PictureBox2, PictureBox3, PictureBox4, PictureBox5, PictureBox6, PictureBox7}
  69.  
  70.         'load list
  71.        terminatorList.Add(PictureBox1)
  72.         terminatorList.Add(PictureBox2)
  73.         terminatorList.Add(PictureBox3)
  74.         terminatorList.Add(PictureBox4)
  75.         terminatorList.Add(PictureBox5)
  76.         terminatorList.Add(PictureBox6)
  77.         terminatorList.Add(PictureBox7)
  78.  
  79.     End Sub
  80.  
  81. End Class
  82.  
RAW Paste Data