-2

In my program I have 20 PictureBox´s which change their visibility about every 5 minutes.

Now I need to count how many PictureBox´s are .visible=true in label1.text.

And how many are .visible=false in label2.text.

Any ideas how to automatically do that?

Gyrocode.com
  • 57,606
  • 14
  • 150
  • 185
  • [This answer](http://stackoverflow.com/a/11166527/242584) will show you how you can iterate through all of the controls on your form, and determine which are PictureBoxes, then you can test each PictureBox's Visible property, and increase a counter for each that is visible. You can then display the result in the TextBox. – Justin Ryan May 28 '15 at 08:55
  • thank you .. but it is not working – Eng. Mohammed Abdo May 31 '15 at 10:18
  • Edit your question to include the code you are trying to run, explain what you expect to happen, explain what you think is actually happening, and include any error messages you receive. – Justin Ryan May 31 '15 at 10:37

1 Answers1

0

Just do something like:

Dim var1 As Integer = 0
Dim var2 As Integer = 0
For Each ctl As Control In Me.Controls
    If TypeOf ctl Is PictureBox Then
        If ctl.visible
            var1+=1
        Else
            var2+=1
        End If
    End If
Next
label1.text = var1.ToString
label2.text = var2.ToString
Sonorpearl
  • 57
  • 7