Controls.AddRange() problem?

philiplcp

Newcomer
Joined
Oct 26, 2004
Messages
10
Does anyone have idea to replace the 'Me.Controls.Add()' to 'Me.Controls.AddRange()' of the following code. I mean is it possible directly add the 'top' into the 'Me.Controls.AddRange()'

Code:
dim focus as ToolPanel
dim panels as new ArrayList
dim top as new ArrayList
....................
For Each focus In panels.ToArray
     focus.Minimize(DockStyle.Top)
     top.Add(focus)
Next
....................
For Each focus In top.ToArray : Me.Controls.Add(focus) : Next
 
philip:
You need to change top to a collection of Controls....I'll try to get the VB right: :p

Code:
Dim top(panels.Count) As Control
Dim count As Int32 = 0

For Each focus In panels.ToArray
    focus.Minimize(DockStyle.Top)
    top(count) = CType(focus, Control)
    count = (count + 1)
Next

Me.Controls.AddRange(top)

philiplcp said:
Does anyone have idea to replace the 'Me.Controls.Add()' to 'Me.Controls.AddRange()' of the following code. I mean is it possible directly add the 'top' into the 'Me.Controls.AddRange()'

Code:
dim focus as ToolPanel
dim panels as new ArrayList
dim top as new ArrayList
....................
For Each focus In panels.ToArray
     focus.Minimize(DockStyle.Top)
     top.Add(focus)
Next
....................
For Each focus In top.ToArray : Me.Controls.Add(focus) : Next
 
You don't need to use AddRange, a control has a Controls Collection. Also, if your not using the top variable anywhere else, you don't need it.

Dim top As Control

For Each focus In panels.ToArray
focus.Minimize(DockStyle.Top)
top.Controls.Add(focus)
Next

Me.Controls.Add(top)
 
Back
Top