Load a control at Runtime

How do I load another instance of a control at runtime.

i.e. Say I have a button on a window and want to copy the button and have another instance of it on the window at runtime, what is required?

  1. Make the button into a Control Array (check the User’s Guide for instructions).
  2. Put the button into a ContainerControl.

From the User’s Guide
If you have a PushButton named PushButton1.
For PushButton1 select New Control Set from the “Member of” popup

In the Action event of the button put the following.

Dim pb As PushButton pb = New PushButton1 //create clone pb.Caption = "Clone" pb.Left = Me.Left + Me.Width + 10

Tim Hare is much more experiences than I am and he may have good reasons for using the ContainerControl.

Tim? Is Damien’s method ok? It looks like what I need

Both Control Sets and ContainerControls allow you dynamically add controls at run-time. ContainerControls are more flexible in that they can handle multiple controls and you can encapsulate things nicely. Control Sets are probably slightly easier to use because you don’t need a separate project item. Both methods should work perfectly fine for what you have described.

Control Sets are fine to use. I included ContainerControl as just another option. Both are good.

Thanks Gents