|
-
Feb 16th, 2005, 03:25 PM
#1
Thread Starter
Member
Copying control from one form to another
I want to (programatically) copy a panel control from one form to a new form, then open the new form. Here's what I've got so far:
Dim frm As New frmOnTop
Dim ctl As Panel
ctl = pnlComments
With frm
.Controls.Add(ctl)
.Text = "Comments"
.Show()
End With
This works, but it removes the panel (pnlComments) from the original form. I just want a copy of it on the new form.
Thanks!
-
Feb 16th, 2005, 06:08 PM
#2
Re: Copying control from one form to another
Because controls are classes and classes are managed by reference, you can't create a copy of a control by simply assigning it to another variable.
Your only options are to either copy each individual property "value" from one control to another, or the recommended way would be to create a user control which contains all the components you want to reuse and then use that whereever you need it.
-
Feb 16th, 2005, 06:21 PM
#3
PowerPoster
Re: Copying control from one form to another
Why not use the code you posted and just reverse it back to form1 when you close form2?
Taxes
The more I learn about VB.NET the more I like dBaseIII Plus
The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|