VB.NET 2003 - form controls automatic setting of parent
Posted on 2004-11-12
I have a form in VB.NET that has many labels and text boxes and what not. I need to set the parent of each one to a picture box that will be in the background. Rather than set each one, as in Me.Label1.Parent = Me. Picturebox1, is there a way to do it programmatically? I've tried this:
Dim ccnt As Integer = Me.Controls.Count
For i = 0 To ccnt - 1
Me.Controls.Item(i).Parent = Me.PictureBox2
The problem is that the number of controls, ccnt, is at 58 when first initialized. When the loop runs, the number of controls gradually decreases. Why? The index eventually gets out of range and aborts. Is there a way to do this or do I have to set each one in the load routine?