How to clone a Control

I know how to clone a control *, but I have a problem with the original one (the one set in the window at design time.

In a loop I add some controls and set their name, location,…

But, in the end, I have one too many, the original one. It can be either a TextField/TextArea with a Label, a PopupMenu, etc.

The Method design is as follow:
a. Open a Text file with instructions,
b. In a While Not Ctrls_TIS.EOF / Wend,
a. I New a Control,
b. I set some of its Properties (Name, x,y,w,h, must add a Label or not, Control Name.
c. When I am out of the loop, I have the first Control(s) to dispose (remove); I cannot (I think) move it out of my window because with Tab(s), the user can access to it.

Ideas ?

  • And my Method to do that works fine, I get my Controls when I get the hand at Window1.Open time.

There is something I lost (forget) while designing that window code.

Ideas ?

Edit:

The code below leads to TWO PushButtons in the target window.

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

make its visible property to false.

And it will no more be accessibles ?

Hi Emile,

Invoke the close method on those rectcontrols you want to dispose (making them no availables and freeing the memory allocated to them).

I will try.

I also set the readonly property to true to be sure, but yes the control is no more in the tab order.

Thanks.

Setting the Control out of the window view (say at x = -10000 for example) is not enough, the Tab will find the Control not in the Window visible area.

@Emile Schwarz — Setting both Control.Enabled and Control.Visible to false should prevent Tab from stopping on your control.