• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 172
  • Last Modified:

Code to remove controls not woking properly need help

I have multiple Picturebox 's that I nee to remove .... the coe I am using sort of works

It will clear them but I have to click multiple times

WHat can I do to clear the PB's that are in mE.PictureBox1.COntrols

Hre it is

Dim ctrl As Control
        '//////// THIS ALMOST WORKS .. just have to click it several times
        For Each ctrl In Me.PictureBox1.Controls
            If TypeOf ctrl Is PictureBox Then
                Me.PictureBox1.Controls.Remove(ctrl)
            End If
        Next

Open in new window

0
vbMarkO
Asked:
vbMarkO
1 Solution
 
jpaulinoCommented:
Try this way:
        While Me.PictureBox1.Controls.Count <> 0
            Dim ctrl As Control
            For Each ctrl In Me.PictureBox1.Controls
                If TypeOf ctrl Is PictureBox Then
                    Me.PictureBox1.Controls.Remove(ctrl)
                End If
            Next
        End While

Open in new window

0
 
vbMarkOAuthor Commented:
Just what I needed thanx works perfectly
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now