Have multiple objects in a With statement in VB?

vb.net

Solution

I would keep those types of items in a list and then apply a for each loop on them, assuming they are all of the same type (or at least base type). Assuming you are using controls of type `label` this would be a solution. Note that I've modified `.fontColor` to `.ForeColor` so that this example works with the Label class:

Dim lblList as new List(of Label) ({lblA, lblB, lblC})
lblList.ForEach(sub(x) x.Fore Color = color.red)

Since you've posted your solution, you could still do the following to avoid the iteration loop over the array you made (which is why I do this as a list) not having to take into account the array size or anything:

 lblList.ForEach(Sub(x)
                    With x
                       .BackColor = Color.Black
                       .Dock = DockStyle.Top
                       .TextAlign = ContentAlignment.MiddleCenter
                    End With
                 End Sub)

Problem

I have a lot of labels in VB that I use in `With` statement to set their properties. Problem Is there any way I can do something like the following: ``` With lblA, lblB, lblC .fontColor = color.Red End With ``` Is this possible, or do I have to manually do a `With` statement for each of them?

Original source