|
-
Nov 22nd, 2002, 07:06 AM
#1
Thread Starter
Lively Member
How to clone a control?
Hi there!
Is there any way I can clone/make a copy of a control without copying properties 1 by 1?
What I'd really like to do, is to have a function receiving a control as input, and then make a new copy of that control.
best reg
BIW
Last edited by biw; Nov 22nd, 2002 at 07:15 AM.
-
Nov 22nd, 2002, 09:40 AM
#2
Dim blah As ControlName = OldControl
???
-
Nov 22nd, 2002, 09:52 AM
#3
Thread Starter
Lively Member
Naww...
That just references the other control, doesn't make a copy
For instance:
VB Code:
Dim txtA As New TextBox()
txtA.Text = "first value"
Dim txtB As TextBox = txtA
txtB.Text = "second value"
MsgBox(txtA.Text)
... returns "second value", not "first value" as desired.
-
Nov 22nd, 2002, 10:06 AM
#4
yay gay
i think is memberclonewise or something like that
\m/  \m/
-
Nov 22nd, 2002, 10:59 AM
#5
Registered User
Create an own TextBox and inherit from System.Windows.Forms.TextBox and implement the ICloneable interface
/Leyan
-
Nov 22nd, 2002, 11:40 AM
#6
You can do something like this:
VB Code:
Dim txt As New TextBox()
'Me.Controls.Add(txt)
Dim pi As Reflection.PropertyInfo
For Each pi In TextBox2.GetType.GetProperties
If pi.CanWrite Then
On Error Resume Next 'just in case
Me.GetType.GetProperty(pi.Name).SetValue(Me, pi.GetValue(TextBox2, Nothing), Nothing)
End If
Next
'txt.Location = New Point(10, 10)
But some it doesn't work so great and I'm not sure why.
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
|