Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 180
  • Last Modified:

Copy of Control

two forms are opened.
now i want to copy all the controls from form1 to form2.
how to do this?
0
anandmehta
Asked:
anandmehta
1 Solution
 
rspahitzCommented:
Select all using mouse, choose copy, switch forms, choose paste.
Repeat for all code in the code Window.

0
 
rspahitzCommented:
Select all using mouse, choose copy, switch forms, choose paste.
Repeat for all code in the code Window.

So, what's the catch?

0
 
MelissaEvansCommented:
At run time or design time?
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
glass_cookieCommented:
Hi!

Why don't you do this: Duplicate the form instead.  Assuming that the form is called Form2,

Add this code to a module:

Public Sub LoadNewDoc()
    Static lFormCount As Long
    Dim frmD As Form2

    lFormCount = lFormCount + 1
    Set frmD = New Form2
    frmD.Show
End Sub

Then, to make a duplicate of Form2, add this line:

LoadNewDoc

By the way, do make sure that you do not use te line:

LoadNewDoc

IN FORM2 ITSELF or there will be a memory overflow.

That's it!

glass cookie : )
0
 
glass_cookieCommented:
Oops!  Sorry about 1 mistake.  You CAN USE IT (ie. LoadNewDoc) in Form2 in the previous case, PROVIDED that you do not place it in the Form_Load() procedure or it would cause the new copy to load another new copy and so on and so forth until all your memory is used up.

That's it!

glass cookie : )
0
 
anandmehtaAuthor Commented:
i want to copy all controls at the run time not at the design time.
0
 
rspahitzCommented:
If might make more sense to simply reference them on on the first form, or make the first form flexible enough to accomodate both.

Why re-invent the wheel if the first wheel has everything you need except one or two things.

The easier way is to build a form that handles both jobs, then set visible=false for those things you don't need at the moment.  Set visible=true when you DO need them.
0
 
Éric MoreauSenior .Net ConsultantCommented:
Create a custom user control and create instances of it on each form.
0
 
glass_cookieCommented:
"i want to copy all controls at the run time not at the design time"

This works during runtime.

Public Sub LoadNewDoc()
   Static lFormCount As Long
   Dim frmD As Form2

   lFormCount = lFormCount + 1
   Set frmD = New Form2
   frmD.Show
End Sub

Then, to make a duplicate of Form2, add this line:

LoadNewDoc
'Load a duplicate of ie. Form2
Note: Do not place LoadNewDoc in the Form_Load() procedure.  You could also change "Form2" to whatever form name you have.

That's it!

glass cookie : )
0
 
glass_cookieCommented:
What would happen would be that an identical Form2 would appear.  Before the frmD.show line, you could add some stuff like frmD.Caption = "Duplicate" or whatever.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now