Migrating Controls from Form to Form

Fabian_Russ

Newcomer
Joined
Sep 29, 2008
I've searched everywhere online and can't find anything on this.

Is there was any way to migrate all controls from form to form?

I've tried

For Each Ctrl as Control in Form2.Controls
Form1.Controls.Add(Ctrl)
Next

I get skipped controls and ect...

but...

If I try to get the name of each control


For Each Ctrl as Control in Form2.Controls
Debug.Print(Ctrl.Name)
Next

It does not skip any and the debugger prints every control's name just fine.

Any Ideas? This is really bothering me.
 

Fabian_Russ

Newcomer
Joined
Sep 29, 2008
I have fixed it! :D

If anyone has the same problem I experienced, Try this!

Me.Controls.Clear()
Dim TempControlRange(1000) As Control
Form2.Controls.CopyTo(TempControlRange, 0)
Me.Controls.AddRange(TempControlRange)

Works like a charm!
 

snarfblam

Ultimate Contributor
Joined
Jun 10, 2003
Location
USA
Could the problem be that you are adding controls to the second form before removing them from the first?
 
Top Bottom